Click here to Skip to main content
12,999,081 members (47,246 online)
Rate this:
Please Sign up or sign in to vote.
I have developed a single server multiple client udp application using multithreading. Now I want to implement the server using asynchronous sockets so that it may be able to handle multiple clients at a time. Will this approach work fine? Is it correct to use asynchronous socket if you want to handle multiple clients using one single server? Is using asynchronous socket a better approach than using threads for handling multiple clients?
Posted 19-Apr-13 0:45am
Matthew Faithfull 19-Apr-13 6:48am
What advantage do you expect from async sockets if you're already using multithreading?
If your server has a thread per client you won't get any. If it is thread pooled you may get a big improvement.
If it is multithreaded and you can still only handle one client at a time you have bigger problems to deal with first.
ayesha hassan 19-Apr-13 7:05am
If I have a single processor system and I can not implement multithreading, what am I supposed to do then in order to handle multiple clients in my server? :(
Matthew Faithfull 19-Apr-13 9:10am
You can still implement multithreading on a single processor system and it can even have some advantages including actually simplifying the code in this kind of application.
There's no reason not to use async sockets it's just that if you have a working multithreaded system already then there's probably no need.

It is also possible to handle multiple clients very well in a single threaded system depending on the protocol in use and how asynchronous, intermitent and granular the overall system is.
It's not easy and some of the basic requirements are:
Each and every message must have a source identifier and message length, these should be at the head of the message.
Messages should be kept small, prefer many small messages over one large one.
Messages must of serialized before reaching your code, i.e. not interleaved with one another and each client must only send one message at a time.
I can't describe a full system for handling this here but it can be done with a lot of thought and a slightly unconventional queueing system. Be very sure this is the way you want to go before trying it.
ayesha hassan 20-Apr-13 1:19am
I have always followed the concept that multithreading can only be implemented on multiple processors system where there are more than one processor to be assigned to each thread and each thread can be executed simultaneoulsy. There is no scheduling in this case as each of the thread has separate resources all dedicated to it.
what is the difference between single processor and multiple processor systems then? :(
I have posted another question here

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.170622.1 | Last Updated 19 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