Click here to Skip to main content
11,934,783 members (47,196 online)
Rate this:
Please Sign up or sign in to vote.
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

1 solution

Rate this: bad
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.[^]
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.[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2015
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