Hello, I'm trying to write a client-server console application on C# using UDP. And i have one question. So, when i send command from client to server - servers must have a read IP adress. client must get some settings from server,but in this case client must have real IP adress too. Other application like games do not require client real IP. What must do I to it work in such a way?
A:
If I understand your question correctly: you could use Socket.ReceiveFrom
, which will tell the server the IP address of the client who is sending a request.
deltreme
2010-07-01 06:56:35
A:
Games either use the host computer with a public IP as a server or the server itself as a server.
A client with private IP establishes a connection with a server and the server then uses the connection to return data to a client (similar to browsers).
In C# you could use the NetworkStream class for TCP and UdpClient for UDP.
Jaroslav Jandek
2010-07-01 06:56:47
UDP is a datagram protocol, NetworkStream is stream-based - i.e. TCP. I believe NetworkStream will NOT work with UDP
Kieren Johnstone
2010-07-01 07:09:29
Oops, you are absolutely correct of course - missed the UDP part. `UdpClient` it is then!
Jaroslav Jandek
2010-07-01 07:26:47
Thanks,that was useful
2010-07-01 21:22:35
A:
Using Socket.BeginReceiveFrom / EndReceiveFrom the server gets the IP address of the client. If the server needs to reply, it uses the IPEndPoint.
harper
2010-07-01 07:51:51