Server Help

Non-Subspace Related Coding - win32/winsock (part 2)

Cheese - Sun Sep 28, 2008 8:00 pm
Post subject: win32/winsock (part 2)

k0zy - Mon Sep 29, 2008 11:30 am
Post subject:
There are two ways of making a multi-client server.

Either you multiplex with "select" or create a new thread/process for each client.

IMO the mutliplexing is harder to code, but easier to maintain. While the thread/process way is easier to code, but harder to maintain because you have to deal with multithreading.

The threaded solution works like this:
- Create the server socket, bind it and start listening.
- Accept a new connection, start a thread and give the new thread the socket descriptor to work with.
- Start accepting new connections right away.
- Handle the connection in the thread.

The mutliplexing solution is a bit harder to explain.
What you do is, store the maximum socket descriptor and loop over all integers from zero to the max and use FD_* to handle the descriptor you are looping over.
This website looks like it's explaining it pretty good:
http://www.lowtek.com/sockets/select.html
I didn't read it, just searched and looked over it.

Attached are the source files for a server I created for an assignment at university, they were written under Linux but it shouldn't take much work to port them.

Before somebody starts complaining: I had to use fork(), we did a threaded solution, too, but I couldn't find it.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group