|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I'm lost while I'm writing a socket network program. My program is working for a single client. But I have no idea how to change my program to works with more than one client. Can anyone give me solution? thanks a lot.
|
|
#2
|
||||
|
||||
|
i am new to this myself, but perhaps i can help. first off though:
is it tcp/ip or udp? if it is UDP, u can get away with a singlethreaded server and a bunch of clients since they dont actually establish a connection. UDP just sends packets back and forth. if it is tcp/ip, i believe u need a multi threaded server to handle more than one client, since a constant connection is being established. |
|
#3
|
||||
|
||||
|
I'm assuming that you're writing a TCP server. Multithreading is one option and about your only option if you're in Windows. If you're doing in Linux/UNIX and are not comfortable with pthreads, you could consider forking a new process.
Either way, the main process/thread is doing the listening. When it accepts a connect, then it can create a new thread or process that will handle the client connected to it and finally return to listening for the next connect to come in. There's an example of a multithreaded TCP server at the site for "The Pocket Guide to TCP/IP Sockets: C Version" by Michael J. Donahoo and Kenneth L. Calvert at http://cs.baylor.edu/~donahoo/PocketSocket/ . Of course, they're using pthreads, but the concepts are pretty much the same under Windows. Actually, they also have Winsock versions of their examples. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > socket problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|