Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello all!

I'm writing small app for sending text data via udp.

On server side i have one async UDP socket for sending and receiving data.
On client side i have same async UDP socket.
When the client sends data to the server, then immediately exit the application without waiting for a response from the server, an error occurs on the server side.

Error: An existing connection was forcibly closed by the remote host.

I understand that this error means and I can re-create the socket on the server, but all clients who at this moment send or receive data also will see an error and will lose some data.

To fix it I can create separate sockets for sending and receiving.But it seems to me that this is the wrong solution. Another idea about this problem is check deads clients, but i don't know how i can do this.

Maybe someone has any idea about this problem?

i'm new in c#....do not swear much =)
Posted

1 solution

Why are you even using UDP? From what you describe, you cannot lose data.

UDP doesn't guarantee the data gets to the destination and doesn't even guarantee the packets show up in the correct order!

What you describe requires TCP, not UDP.

UDP is used to broadcast connectionless data that tolerates packet loss, such a streaming video.

If you're holding a conversation with a server, use TCP instead.
 
Share this answer
 
Comments
Jak Vo 2-Jul-15 16:00pm    
I can't use tcp.My clients send only keys ( like "w" "a" "s" "d" ) and if some data lost is not a problem. I need fast server,and i can use only UDP....
Dave Kreskowiak 2-Jul-15 17:21pm    
So you need a ton of performance? That precludes you from "seeing" if the client is really there. Also, you can't really find out reliably either.

First, your only method of finding out if a client MAY be there is to ping it. Remember, UDP is connectionLESS so you have no way of asking the network stack if the client is there. The problem with ping is that it will slow your data sender WAY down as you are sending a ICMP packet over TCP/IP to the client and waiting for a return.

On top of that, what if the network path between your server and the client disappears between the time you check for the client and the time you start sending data? Yeah, not reliable.

You have no choice but to improve your sending code to handle the situation where the client unexpectedly disappears.
Sergey Alexandrovich Kryukov 2-Jul-15 18:17pm    
Sounds reasonable to me, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900