views:

53

answers:

3

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
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
UDP is a datagram protocol, NetworkStream is stream-based - i.e. TCP. I believe NetworkStream will NOT work with UDP
Kieren Johnstone
Oops, you are absolutely correct of course - missed the UDP part. `UdpClient` it is then!
Jaroslav Jandek
Thanks,that was useful
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