我正在测试MSDN上的异步客户端/服务器示例。它工作正常。服务器示例https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-server-socket-example和客户端示例https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example
我正在尝试检查是否可以添加一些自定义服务器“版本”标记。因此,客户端需要指定版本号才能获得有效连接。这不是我需要的默认TCP三方握手。这是在服务器上添加的额外自定义版本号,并在我正在寻找的客户端上的连接字符串中指定。
我可以在套接字中添加一些“版本”对象吗?
// Establish the remote endpoint for the socket.
// The name of the remote device is "host.contoso.com".
IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
Socket client = new Socket(ipAddress.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
// Connect to the remote endpoint.
// TODO: How to add custom version object?
client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client);