FD_ACCEPT和FD_CONNECT哪個先觸發啊,我看介紹說好像FD_ACCEPT先觸發,可為啥我除錯時總是先蹦到FD_CONNECT?
uj5u.com熱心網友回復:
你概念搞錯了基于TCP(面向連接)的socket編程,分為客戶端和服務器端。
客戶端的流程如下:
(1)創建套接字(socket)
(2)向服務器發出連接請求(connect)
(3)和服務器端進行通信(send/recv)
(4)關閉套接字
服務器端的流程如下:
(1)創建套接字(socket)
(2)將套接字系結到一個本地地址和埠上(bind)
(3)將套接字設為監聽模式,準備接收客戶端請求(listen)
(4)等待客戶請求到來;當請求到來后,接受連接請求,回傳一個新的對應于此次連接的套接字(accept)
(5)用回傳的套接字和客戶端進行通信(send/recv)
(6)回傳,等待另一個客戶請求。
(7)關閉套接字。
uj5u.com熱心網友回復:
這個流程我知道,我就想知道是不是客戶端先connect,然后服務端觸發FD_ACCEPT訊息,服務端呼叫accept函式后,客戶端再觸發FD_CONNECT訊息?
uj5u.com熱心網友回復:
服務器等待客戶端的Connect 再接受連接請求acceptuj5u.com熱心網友回復:
一個在Server 一個在Clientuj5u.com熱心網友回復:
FD_ACCEPT:When WSAAsyncSelect called, if there is currently a connection request available to accept.
When a connection request arrives, if FD_ACCEPT not already posted.
After accept called, if there is another connection request available to accept.
FD_CONNECT:
When WSAAsyncSelect called, if there is currently a connection established.
After connect called, when connection is established, even when connect succeeds immediately, as is typical with a datagram socket.
After calling WSAJoinLeaf, when join operation completes.
After connect, WSAConnect, or WSAJoinLeaf was called with a nonblocking, connection-oriented socket. The initial operation returned with a specific error of WSAEWOULDBLOCK, but the network operation went ahead. Whether the operation eventually succeeds or not, when the outcome has been determined, FD_CONNECT happens. The client should check the error code to determine whether the outcome was successful or failed.
uj5u.com熱心網友回復:
accept是等待連接的意思,因此accept是先于connect開始,等連接完成后晚于connect再結束。uj5u.com熱心網友回復:
FD_ACCEPT和FD_CONNECT 兩個事件觸發啊轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/68704.html
標籤:網絡編程
上一篇:OPENCV2.4.11+vs2015 Release生成問題
下一篇:MFC顯示影像的問題
