Skip to main content
gamedev.net
🔒 Locked

Handle multiple users

Started by Decrius 10 replies 2.1k views
Original Post
Decrius
Decrius
So, I want to make a server-client model (did a client-client model before) where multiple clients should be able to connect to the server. I was thinking of 1 to ~10 clients connected, but to make my app scalable, I want it to be able to have ~100 till ~1000 connections. How would I handle all these connections? How would I be able to respond to anything the client is sending to me if I have 999 other people waiting for an answer? I could use a SocketSet as I did with SDL_net (http://jcatki.no-ip.org:8080/SDL_net/SDL_net_frame.html), or I could make new threads per connection. While I prefer the first method, I somehow feel that making threads will improve the speed/ability to react to multiple clients. What should I use? What do you guys use? Thanks, Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Antheus
Antheus
Quote:
Original post by Decrius

While I prefer the first method, I somehow feel that making threads will improve the speed/ability to react to multiple clients.


For up to 10 clients, under certain models, threads even might, or at least be on par. Otherwise non-blocking sockets will likely be your best choice.

Under Windows, IOCP will bring you upwards of thousand, and even well above 10,000 with semi-decent hardware. Linux offers AIO for same task. All obviously depends on amount and pattern of traffic.
Decrius
Decrius
Ah okay, what library would you advice? I'm looking for a cross-platform library, I used SDL_net before, worked quite good, but since I use OpenGL (and GLFW) I don't want to add all the SDL functions while I won't use them.

And, I'm trying to build a very simple 2D game (who doesn't :P), data would be send at least once per second, where the position of objects would be send etc. So that would mean the server has to handle at least ~1000 responses to clients per second. Ofcourse it depends on how well you build the server, but also on the library you use and its abilities (like 'non-blocking' sockets (not sure what it is though)).

What library would be a good choice? (C++)
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Antheus
Antheus
Quote:
Original post by Decrius
Ah okay, what library would you advice? I'm looking for a cross-platform library,


See Forum FAQ.

Quote:
Ofcourse it depends on how well you build the server,


It will depend on your architecture. How often and how much you send, do you update all clients, do you update full states, LAN or Internet, ..., as well as type of game, FPS, RTS, MMO, P2P, Web-based....

[Edited by - hplus0603 on March 10, 2008 6:34:39 PM]
Spodi
Spodi
Worry about scalability when scalability is an issue. You could literally spend the rest of your life making your server perform the best it can but most of the time it is just going to go to waste.

If you want to do anything to prepare for the future, keep your server code nice and separate from other parts of the project so that it won't be much of an issue to improve on the code when it is needed.
NetGore - Open source multiplayer RPG engine
Antheus
Antheus
Quote:
Original post by Spodi
Worry about scalability when scalability is an issue. You could literally spend the rest of your life making your server perform the best it can but most of the time it is just going to go to waste.


That's not entirely true.

There are 3 types of networking. Blocking, non-blocking and event-based. Experience and various studies have shown that blocking has poorest scalability, and event-based best.

While event-based can scale better than non-blocking, it imposes a different programming model which may be more difficult to manage.

Saying that worrying about scalability last isn't best advice. If so, why not start writing a game client WinForms? I mean, once your game is complete, you can trivially convert it to DX10 shader pipeline. Right?

General performance of some code can be described as O(n) + C.

- Optimization reduces the C
- Scalability reduces the O(n)
samoth
samoth
Quote:
Original post by Decrius
Ah okay, what library would you advice? I'm looking for a cross-platform library
Have a look at libevent (http://monkey.org/~provos/libevent/).
libevent lets you multiplex between many connections, it's lightweight, and as much cross-platform as you can go.

Decrius
Decrius
So it is better to go through all open sockets then spawning thread per socket? Or would it be better to spawn a new thread every 100 sockets for instance?

Quote:
Original post by Antheus
General performance of some code can be described as O(n) + C.

- Optimization reduces the C
- Scalability reduces the O(n)


I don't really understand what you mean by that, what is O(n) and C?

Quote:
Original post by samoth
Have a look at libevent (http://monkey.org/~provos/libevent/).
libevent lets you multiplex between many connections, it's lightweight, and as much cross-platform as you can go.


Ok thanks, I will try it out. Though ENet looked good too, the problem is that I always have trouble with making the library files...

[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
hplus0603
hplus0603
If you like C++, I also suggest looking at boost::ASIO. It is a general asynchronous I/O library, that happens to also work on sockets. It's highly portable.

In an expression like "k*O(n) + C" the formula gives the expected runtime of a given operation, as a function of the number of items being operated on (n). Optimization can reduce the value of k and C. However, when O(n) is expressed as something like "n squared" then, for large n, the fact that n squared grows faster than k (or C), means that the scalability is more important than the optimization.

For more information on big-O notation, look it up in your favorite "introduction to algorithms" textbook.
enum Bool { True, False, FileNotFound };
Spodi
Spodi
Quote:
Original post by Antheus
Quote:
Original post by Spodi
Worry about scalability when scalability is an issue. You could literally spend the rest of your life making your server perform the best it can but most of the time it is just going to go to waste.


That's not entirely true.

There are 3 types of networking. Blocking, non-blocking and event-based. Experience and various studies have shown that blocking has poorest scalability, and event-based best.

While event-based can scale better than non-blocking, it imposes a different programming model which may be more difficult to manage.


This is what I meant by keeping it separate from the project. Of course blocking, non-blocking and event-based sockets are going to have different implementations, similarities even growing farther from the rest as you optimize and better utilize the design, but given Decrius's post, I am assuming he doesn't have a lot of background in networking. Telling him to use event-based networking could easily be far over his head. I wasn't saying it is not worth doing if you need to / can do it, but it is not worth doing if you do not need nor understand it.
NetGore - Open source multiplayer RPG engine
Decrius
Decrius
Quote:
Original post by Spodi
This is what I meant by keeping it separate from the project. Of course blocking, non-blocking and event-based sockets are going to have different implementations, similarities even growing farther from the rest as you optimize and better utilize the design, but given Decrius's post, I am assuming he doesn't have a lot of background in networking. Telling him to use event-based networking could easily be far over his head. I wasn't saying it is not worth doing if you need to / can do it, but it is not worth doing if you do not need nor understand it.


Yeah, I just made a simple chat TCP server-client application before, so I have some basic knowledge. But I have no idea what (non-)blocking/event-based is.

Also, I've been looking for some network libraries. ENet looked good, though boost.ASIO too. I couldn't get to build ENet in CodeBlocks -.-, haven't tried asio (needed the boost package too...just seemed to heavy-weight at first glance).

[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
rip-off
rip-off
Boost seems heavy in the same way as a toolbox feels heavy, you'll need the tools either way. Unless you plan on making all the tools yourself when you arrive at a job (hint: not a great idea [smile]).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.