I just started socket programming with .net using C# and I had a question regarding an experimental server and client I was building on my machine.
My task is to make the client communicate with the server through port 2004, and the server with the client through port 2010. So meaning that the server receives messages in port 2004, and send them in port 2010. I however am struggling to implement this. Does this for example mean that the server has a local endpoint of 2004 and a remote endpoint of 2010? Or should I make 2 different sockets for this? Right now my code looks like this:
Client
Socket sock;
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
IPEndPoint clientEndpoint = new IPEndPoint(ipAddress, 2010);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 2004);
EndPoint remoteEP = (EndPoint)sender;
sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sock.Bind(clientEndpoint);
Server
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Any, 2010);
remoteEP = (EndPoint)remoteEndpoint;
IPEndPoint localEndpoint = new IPEndPoint(ipAddress, 2004);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.Bind(localEndpoint);
I've tried sniffing around other questions on Stackoverflow and also read the Socket documentation on learn.microsoft.com but I couldn't really figure out how to do this. I was also wondering how I would have to use ReceiveFrom and SendTo in this situation, but I am assuming I just receive and send to the remote endpoint?