Click here to Skip to main content
15,070,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am working on udp server/cient application. I want my Server to be able to handle 40 clients at a time. Right now I am using the approach of creating one receiving thread which continuously receives data and one sending thread for sending data if required. Since the socket queue is large enough to buffer data from 40 clients so I am using only one receiving thread. What might be other possible ways to implement such single server multiple client application?
Posted

The other, quite obvious, approach would be creating a thread per client (well, two threads per client).
The adavantage would be a somewhat simpler code.
   
Comments
ayesha hassan 15-Apr-13 8:08am
   
For that do I need one main receiving thread and distribute the incoming clients on the basis of their IP addresses to specific threads?
CPallini 15-Apr-13 8:11am
   
Yes, that's the usual architecture of a multiple connections server.
Your approach is reasonable. Keep the sending and receiving threads simple.

Use queues to buffer the data for the clients. Create a queue for each client. You could have a pool of threads, then processing incoming packets from those queues.

As CPallini mentions, you could create a seperate thread for each client.

The downside is that if your client threads need to do any heavy processing, they could miss packets. UDP doesn't gurantee delivery or have a mechanism to tell the sender to quit sending, that the queue is full...
   

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