so i implemented a simple udp server, that creates a socket and listens on it. I created a simple udp socket like this:
IPEndPoint ip_endpoint = new IPEndPoint(IPAddress.Any, Port);
udp_server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
udp_server.Bind(ip_endpoint);
with IPAdress.Any i make sure, that the socket accepts packets from any source. Then in a loop i receive any incoming packets with:
udp_server.ReceiveFrom(receive_buff, ref remote_endpoint);
On the client side i do the same thing, except using an explicit ip-adress to connect to the desired server.
This works perfectly, and i can even handle multiple clients with a little bit more work. However, when i close the socket on the client side, the server throws an error on the ReveiveFrom line saying that the connection has been closed. This does not make any sense to me for the following two reasons:
- UDP should not be a connection-based protocol if i remember correctly.
- I have multiple clients. Even if one of the clients is closed, i should be able to receive from other clients.
Why is this error thrown then? I would like to just ignore this, but the socket just keeps throwing the error when receiving on the server, even tho other connections still might be fine. How do i handle this?