hi everyone,

I am working on winsock programming stuff now, but I am having problem of understanding how multi sockets works.

I like to know how it done in programs like MIRC or FTP clients.

how can they handle that much connections? and when sending file, how to figure out which is which socket???

can someone help me out here please??

thankx in adv.:alright:
Posted on 2002-02-26 03:31:07 by Yanda
There are different ways to handle multiple incoming connections. Apache 1.3 starts a new instance of it's process each time a new connection is made. This is a way to do it but it is not as scalable as a multi-threaded solution. Apache 2 is now multi-threaded. Multi-threading involves spawning a new thread for each new connection. The toughest part with multiple threads is to make sure they are synchronized so as not to step on each other's toes trying to write to the same memory area or something. Make a search on the boards about it. There was just a discussion the other day on this subject. Maybe EvilHomer or Bazik have some examples they can share.
Posted on 2002-02-26 11:39:03 by rdaneel
study that (and much much more!) stuff from this book. :)

Posted on 2002-02-26 12:41:24 by latigo
thankx for da replies,

hm,, so u mean multithreading is like this:

create a newthread, within the newthread, create a new socket for listening incoming connection?

so is basically I have to create a new socket for every incoming connection?? if that is the truth, how can it be handle the socket descriptors?? how do I know which is which when there are like ova 100+ connections???
Posted on 2002-02-26 19:18:41 by Yanda
No that is incorrect. You just need one listening socket. After you create the socket with socket() and define your callback message with WSAAsyncSelect(), just begin monitoring for FD_ACCEPT messages in your WndProc when you receive your callback message. Winsock will assign a unique socket descriptor for each incoming connection made to your listening socket and place it in wParam. In a multithread app you just accept each new connection at this point and spawn a new thread with CreateThread(). The function that CreateThread() points to should be your handler routine. Again, watch out for thread syncing. I'm no good with that subject so someone else will have to answer those questions. You really should grab some multisock source off the boards and read through it to get a grasp.
Posted on 2002-02-26 23:52:46 by rdaneel
thankx alots rdaneel!!!!!

now I got the idea of how server works! thankx alots!!!

Posted on 2002-02-27 00:12:35 by Yanda