6TTW014
6TTW014

Reputation: 627

C# Log Socket Connections

I've no idea how I would go about this but I'm assuming that it is possible in some way, shape or form.

  1. If I have a server that allow multiple connections to it through one port, is there a way I can make some sort of log of the connections, so that I could choose a certain connection to send a message to? Also if this is possible.

  2. Is it also possible to do the same with connections through different ports?

  3. How would I go about this? I'm fairly new to C# so not very experienced - any help is greatly appreciated!

Basically I want 3 clients to connect to a server. The clients will all send a message to the server, and the server will wait for a message from each client before replying to them, in the order in which the messages were sent.

I hope this makes more sense now.

Upvotes: 0

Views: 1327

Answers (1)

C.Evenhuis
C.Evenhuis

Reputation: 26446

If you are using TCP/IP, this is very much possible - the Socket that listens for incoming connections only does that - it does not handle the communication with each individual socket. Instead, the Accept() and BeginAccept() methods return a new Socket instance for each client that connects.

So the Socket instance you get when a client connects only receives messages from that client, and sending a message on that socket sends it to only that client.

Keeping track of which connection sent what - and which came first - will be more of a challenge, but definately possible.

If you are using UDP though things are a bit different, you would need to use a custom means of identifying each client.

Upvotes: 1

Related Questions