Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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
Comments
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 http://www.codeproject.com/Questions/580778/Canplusmultithreadingplusbeplusimplementedplusonpl

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