淺談socket TCP編程中connect的一些坑
1.服務(wù)端listen成功后,系統(tǒng)就自動接收客戶端請求了
man listen:
其中有一段
The behavior of the backlog argument on TCP sockets changed with Linux
2.2. Now it specifies the queue length for completely established
sockets waiting to be accepted, instead of the number of incomplete
connection requests. The maximum length of the queue for incomplete
sockets can be set using /proc/sys/net/ipv4/tcp_max_syn_backlog. When
syncookies are enabled there is no logical maximum length and this set‐
ting is ignored. See tcp(7) for more information.
也就是說,listen成功后,系統(tǒng)會自動接受bocklog個客戶端請求,并不需要服務(wù)端accept,就算服務(wù)端沒有accept,客戶端connect仍然返回成功。accept僅僅是從backlog隊列中取出一個已經(jīng)建立了完整TCP連接的套接字。
2.一個fd socket了connect后,不能再次connect
再次connect,會報錯:Transport endpoint is already connected
此時想要再次connect,必須重置fd..
連接建立后socket的狀態(tài)被置為SS_ISCONNECTED,因此在調(diào)用close重置此socket狀態(tài)之前,會報錯。。
以上就是小編為大家?guī)淼臏\談socket TCP編程中connect的一些坑全部內(nèi)容了,希望大家多多支持腳本之家~
相關(guān)文章
標(biāo)準(zhǔn)C++類string的Copy-On-Write技術(shù)
這里,我想從C++類或是設(shè)計模式的角度為各位揭開Copy-On-Write技術(shù)在string中實現(xiàn)的面紗,以供各位在用C++進(jìn)行類庫設(shè)計時做一點參考2013-11-11C++使用HDF5庫實現(xiàn)將h5圖像轉(zhuǎn)為tif格式
這篇文章主要為大家詳細(xì)介紹了C++ 語言如何通過hdf5庫與gdal庫實現(xiàn)將.h5格式的多波段HDF5圖像批量轉(zhuǎn)換為.tif格式,有需要的可以參考一下2024-12-12