Connecting Tech Pros Worldwide Forums | Help | Site Map

multi client to server in C#

Member
 
Join Date: Feb 2008
Location: M'sia
Posts: 33
#1: Dec 7 '08
Hi guys:
This topic might sound very familiar to some of you, can some one shed some light or point me to some web link for some sample code or good guide?

I'm able to code for a simple client to server ( one to one) but not this multi client scenario.

The application that i want to establish is simple:

clientx.1--------------> send a request to server for a job
clientx.2--------------> send a request to server for another job
..
....

all this activities have to be concurrent...

how to do this?


Thanks

Member
 
Join Date: Nov 2008
Posts: 58
#2: Dec 8 '08

re: multi client to server in C#


Quote:

Originally Posted by Jetean View Post

Hi guys:
This topic might sound very familiar to some of you, can some one shed some light or point me to some web link for some sample code or good guide?

I'm able to code for a simple client to server ( one to one) but not this multi client scenario.

The application that i want to establish is simple:

clientx.1--------------> send a request to server for a job
clientx.2--------------> send a request to server for another job
..
....

all this activities have to be concurrent...

how to do this?


Thanks

Use ThreadPool wherein you can run your client(s) separately on thread(s).
ie clientx.1-> will run on Thread1
clientx.2-> will run on Thread2...
Member
 
Join Date: Feb 2008
Location: M'sia
Posts: 33
#3: Dec 8 '08

re: multi client to server in C#


Hi:

Are you suggesting to have multiple server running on multiple thread?

Is this viable?

Thanks
Member
 
Join Date: Nov 2008
Posts: 58
#4: Dec 8 '08

re: multi client to server in C#


Quote:

Originally Posted by Jetean View Post

Hi:

Are you suggesting to have multiple server running on multiple thread?

Is this viable?

Thanks

No no... Its about client. You can have your client on a separate thread which communicates to the server. If you have common resources across the clients, you may have to opt synchronization between your clients.
Expert
 
Join Date: Sep 2008
Location: USA
Posts: 188
#5: Dec 8 '08

re: multi client to server in C#


Can you please clarify what design you are using for "client/server."
Are you using Remoting, WebServices, or hand-coded socket communication?

Are these truly separate clients talking to one server in a separately compiled server application or listener?

If so, what protocol do you use to send and receive job requests?

Mike
Member
 
Join Date: Feb 2008
Location: M'sia
Posts: 33
#6: Dec 8 '08

re: multi client to server in C#


OK. I'm using Socket. The application is to serve multiple PCs within the same office. 1 server and multiple clients. I think i can handle the client side but I'm not sure about the Server side program. How to do it?
Member
 
Join Date: Feb 2008
Location: M'sia
Posts: 33
#7: Dec 8 '08

re: multi client to server in C#


One more condition is that The Server has to continously scan for any new connection and new incoming request..
Expert
 
Join Date: Sep 2008
Location: USA
Posts: 188
#8: Dec 9 '08

re: multi client to server in C#


For the listener, I would suggest you start by studying the System.Net.Sockets.TcpListener class, as this will take care much of the infrastructure of listening for socket connection requests and reading them.
Member
 
Join Date: Feb 2008
Location: M'sia
Posts: 33
#9: Dec 10 '08

re: multi client to server in C#


mldisibio:
I'm looking at Asynchronous TCP Server. I'm not quite sure how to implement it. With many Clients sending data back to Server, Will one Client Keep Connected to the server preventing access from other Clients?
Member
 
Join Date: Nov 2008
Posts: 58
#10: Dec 10 '08

re: multi client to server in C#


Is it something like your TCP SERVER(which you will be developing) has to perform normal tasks(irrespective of the operations) along with SERVING YOUR CLIENTS(each client is a separate PC)! Are you seeking Asynchronus SERVER for this purpose?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#11: Dec 10 '08

re: multi client to server in C#


The 'de facto' way to do this is to run a simple loop that accepts new clients. Once accepted the new socket/client is passed to a new thread that serves the client through that socket. Once done, the thread simply dies. Shared resources should be synchronized among the several client serving threads.

kind regards,

Jos
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#12: Dec 10 '08

re: multi client to server in C#


Jos is actually right (pause for recovery of blockbuster news).

Generally, you will have thread that sets up the listener socket, loops around accepting connections (syncronous or asyncronous), and starts a new thread for each new connection.
Thread loop should take steps to not be a busy loop.

Each of your spawned threads will handle interaction with the connected client.

This is similar to the way a webserver works.
Reply