0

Edit: Yes I know that UDP doesn't technically connect, but you can still use it to set the default target for Send(), which is what I'm doing here.

Basically I have this problem that between calls to MySocket.Send(), MySocket is becoming disconnected i.e. the Connected variable becomes false (I know that Connected isn't necessarily up-to-date, but no data isn't being sent so I know that it's telling the truth).

The strange thing is that the RemoteEndPoint variable is still set correctly, but when I call Send(), no data is recieved by the other computer. However if I call Connect() again, the socket does connect, and I'm able to send data (at least until the next time the user does something that causes another call to Send() )

Can anyone tell me why a socket would spontaneously disconnect?

The line where I connect it is:

 opep = new IPEndPoint(Opponent.Address, 1000);
 Listener.Connect(opep);

I don't see anything here that could be garbage collected for example to cause this issue.

Thanks!

Migwell
  • 18,631
  • 21
  • 91
  • 160
  • Does this answer your question? [C# Async UDP listener SocketException](https://stackoverflow.com/questions/5199026/c-sharp-async-udp-listener-socketexception) – jmik Nov 19 '21 at 13:43

1 Answers1

-1

UDP doesn't set up a connection. You should check out the following link for more info

Difference between TCP and UDP?

Community
  • 1
  • 1
Rik
  • 316
  • 3
  • 19
  • 1
    UDP doesn't *need* a connection, but you can still use the method to set the default target for Send(). – Migwell Nov 11 '13 at 11:49