Click here to Skip to main content
15,891,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have developed a udp application in which a single server is able to handle 'x' number of clients. Inside my server, there is a primary thread keeps on receiving requests/data continuously from the clients and keeps saving the information of each client in a list.

As soon as a request comes from a new client(i.e. from a client that whose information is not saved in the list), a new thread is launched and a separate socket is created for serving that specific client. In other words, for each client, there is a separate socket and a separate dedicated thread.

Now, the problem that I foresee is that since there is only one socket i.e. single line for communication, there are chances that if both Server and Client send data at the same time, there are chances of data collisions.

How shall I cater such a situation? Waiting for response :(
Posted
Updated 30-Apr-13 1:35am
v2

1 solution

It depends on how much clients do you expect and how large messages will be sent.
The issue is that UDP does not guarantee delivery of data by itself, so some packets could be dropped.
http://technet.microsoft.com/en-us/library/cc785220(v=ws.10).aspx[^]
Simultaneous data sending both by sender and receiver will be critical with a large amount of connections. Even if you create your own protocol layer upon UDP to count number of messages sent, CRC etc to reduce data loss there will be a issue with a maximum thread count.
So if your solution designed in a right way, there will be no problems with tenths of clients but still there is a chance of flooding.
UDP should be reliable enough for fast connections and fair simple in realization, but for some cases I would prefer a completion ports.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365198(v=vs.85).aspx[^]
 
Share this answer
 

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