Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Windows programming udp , +
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 30-Apr-13 2:22am
Edited 30-Apr-13 2:35am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 OriginalGriff 240
2 CPallini 195
3 Maciej Los 177
4 BillWoodruff 173
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100