0

Im testing the async client/server example on MSDN. It works fine. The server example https://learn.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-server-socket-example, and the client example https://learn.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example

I'm trying to check if I can add some custom server "version" tag. So the client need to specify the version number in order to get a valid connection. It's not the default TCP Three Way Handshake I need. It's a extra custom version number added on the server and specified in the connection string on the client I am looking for.

Can I add some "version" object to the socket?

// 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);
vemund
  • 1
  • 4
  • Why can't you just have it connect, let the server send a version challenge to the client, have the client respond, and if it's not to the server's liking, have the server forcibly close the connection? Protocols like TCP/IP are fairly settled, and would get very messy if you could add in your own stuff, this is more application-level protocol stuff, so your app should handle this sort of thing. – Clint Dec 19 '17 at 11:05
  • @Clint thanks! Found this https://stackoverflow.com/questions/284885/multi-client-async-sockets-in-c-best-practices after reading your reply. – vemund Dec 19 '17 at 11:41
  • no problem, I've marked it as a duplicate, please keep the question here so people with the same problem can follow the trail. – Clint Dec 19 '17 at 11:54

0 Answers0