ListenSocket ClientSocket Go

ヤンヤン建:

、この記事についてGo Web Server、そこにいるListen SocketClient SocketしてGo

GoLangが1つのソケットListen Socket, Client Socketだけでなく2つのソケットを必要とする理由を理解できません。その概念を説明したり、比喩を書いたりできますか?

編集:私は私の答えを更新します。

ヤンヤン建:

たぶん私は多分、グラフまたはグラフは非常によく描画されていない誤解Listen SocketClient Socket同じソケット、ソケットがクライアントからの接続を受け付けていない場合、それを呼び出しているListen Socket、そしてそれは、接続を受け入れた後、それが名前を変更していますClient Socket、1つのソケットだけがありますステージと名前が異なります。


更新1:

Socket Working Hereに関するより良い記事とグラフを見つけました

記事の概要では、新しい接続があるときは明らかです。TCPサーバーは、接続を処理するための新しいソケットを作成し、Listen Socket他の接続の待機を継続します。

これが記事の段落です:

を介してTCPサーバーによって作成された最初のソケットNetSock_Open()は通常と指定され、listen socketへの呼び出し後NetSock_Listen()、サーバーがさまざまな接続要求に応答できるように、無期限に開いたままになります。このソケットを使用して要求側クライアントとデータを交換するのではなく、サーバーは要求ごとに新しいソケットを作成します。


アップデート2

最初の更新は、Micrium社に取り組んでいるので、私は別のを見つけ、より一般的なTCPの作業instuctionようだ。ここ

TCP connection flow The following sequence shows the flow of a TCP

connection:

  1. The server creates the listener socket that is waiting for remote clients to connect.

  2. The client issues the connect() socket function to start the TCP handshake (SYN, SYN/ACK, ACK). The server issues the accept() socket function to accept the connection request.

  3. The client and server issue the read() and write() socket functions to exchange data over the socket.

Note: There are several SSL APIs that you can use to send and receive data other than the read() and write() socket functions.

  1. Either the server or the client decides to close the socket. This causes the TCP closure sequence (FINs and ACKs) to occur.

  2. The server either closes the listener socket or repeats beginning with step 2 to accept another connection from a remote client.

Note: Normally after the accept() socket function ends, the server divides into two processes (or threads). The first process handles the connection with the client and the second process issues the next accept() socket function. Figure 1 shows an example of a TCP connection:


Note:

  1. I find another Socker Programming Tutorial mention about working detail in TCP.

  2. And In .NET Framework MSDN, the explanation about Socket.Accept Method() says Accept synchronously extracts the first pending connection request from the connection request queue of the listening socket, and then creates and returns a new Socket.

  3. I have skimmed RFC about TCP before Update 1, but I didn't see it mention the detail that Listen use one socket, and when Accept it'll create another new Socket.

  4. Maybe the thorough way is to research the Source Code about Create Socket and Connection in Go, but I'm not consiedring to do it now.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事