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 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 15-Apr-13 2:53am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
ayesha hassan at 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 at 15-Apr-13 8:11am
   
Yes, that's the usual architecture of a multiple connections server.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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...
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 15 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