0

我开始在 C# 中进行套接字编程。我查看了几个示例程序,它们打开一个套接字,从套接字获取一个流并使用相同的流从客户端读取数据并将数据写入客户端。这究竟是如何工作的?我原以为必须有两个单独的流——一个供服务器读取,一个供它写入。套接字如何区分服务器要读取的数据和服务器要写入的数据?

4

1 回答 1

3

Internally there are two buffers - incoming data that you can read, and outgoing data that you have written. You drain the first buffer, and the implementation re-fills it by reading from the socket. You push your data into the second buffer, and the implementation drains it by writing to the socket.

于 2012-12-10T14:44:52.520 回答