Click here to Skip to main content
13,050,617 members (93,929 online)
Rate this:
Please Sign up or sign in to vote.
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 1:53am
Rate this: bad
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.
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.
Rate this: bad
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...

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
Web02 | 2.8.170713.1 | Last Updated 15 Apr 2013
Copyright © CodeProject, 1999-2017
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