淺談socket TCP編程中connect的一些坑
1.服務(wù)端listen成功后,系統(tǒng)就自動(dòng)接收客戶端請(qǐ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)會(huì)自動(dòng)接受bocklog個(gè)客戶端請(qǐng)求,并不需要服務(wù)端accept,就算服務(wù)端沒有accept,客戶端connect仍然返回成功。accept僅僅是從backlog隊(duì)列中取出一個(gè)已經(jīng)建立了完整TCP連接的套接字。
2.一個(gè)fd socket了connect后,不能再次connect
再次connect,會(huì)報(bào)錯(cuò):Transport endpoint is already connected
此時(shí)想要再次connect,必須重置fd..
連接建立后socket的狀態(tài)被置為SS_ISCONNECTED,因此在調(diào)用close重置此socket狀態(tài)之前,會(huì)報(bào)錯(cuò)。。
以上就是小編為大家?guī)淼臏\談socket TCP編程中connect的一些坑全部?jī)?nèi)容了,希望大家多多支持腳本之家~
相關(guān)文章
標(biāo)準(zhǔn)C++類string的Copy-On-Write技術(shù)
這里,我想從C++類或是設(shè)計(jì)模式的角度為各位揭開Copy-On-Write技術(shù)在string中實(shí)現(xiàn)的面紗,以供各位在用C++進(jìn)行類庫設(shè)計(jì)時(shí)做一點(diǎn)參考2013-11-11C++使用HDF5庫實(shí)現(xiàn)將h5圖像轉(zhuǎn)為tif格式
這篇文章主要為大家詳細(xì)介紹了C++ 語言如何通過hdf5庫與gdal庫實(shí)現(xiàn)將.h5格式的多波段HDF5圖像批量轉(zhuǎn)換為.tif格式,有需要的可以參考一下2024-12-12