Client-Server connection

Started by
7 comments, last by deadstar 16 years, 4 months ago
I'm very new to this Network Programming and just wanting to get involved a little bit by asking a (more than likly stupid) question. In looking about at tutorials for programming with WinSock there was an example that used an exe acting as a server and then an exe that acted as the client. When looking at the code for the server it was very much designed for the client, is this normal? or could i make a more general purpose simple server that can be used for many different games? Is the first way more efficient? As i said i am VERY new to this so any feedback would be nice (go easy on me) Thank you
Advertisement
The server has to be able to cope with anything the client sends it. You can't really make a general purpose server for any game, but you could make a server that would be general purpose for all of your games.

If you make all your games use a message/packet based system, all you need to do is give each message a unique ID, and make sure that two games IDs don't overlap. That's easier said than done, unfortunately.


Generally though, you write the server for just the one game.
Thank you very much, I think I will just stick to making the server for each game then, in an effort to not over complicate things.
I'll make sure I learn more about network programming as I develop games for fun.
It helps to make a plan before you start. Make yourself a text file and start filling it with all the network commands you think your game might need, and start assigning them ID's.

It really helps, I've started planning like this before I do anything these days, I'm currently just finishing a custom 3D model file format, and without a big text file of planning it would have been a nightmare.

Plus, you'll be able to figure out beforehand how many digits the maximum ID is, I.E., if you came up with 130 commands, you need three characters sent for the ID, which allows you up to 999 commands just in case. If you only come up with 20, use two characters, that gives you 99 to play with.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

I am a bit of a bugger when it comes to planning, i tend to jump in feet first, not the best way to go about things ^_^ but i am starting to plan things more often now. That sounds like a really good idea though so i will take that on board definatly, Thank you deadstar.
Quote:Original post by deadstar
I.E., if you came up with 130 commands, you need three characters sent for the ID, which allows you up to 999 commands just in case. If you only come up with 20, use two characters, that gives you 99 to play with.


Or just use a single byte which can store up to 256 unique id's...

Quote:Original post by deadstar
Plus, you'll be able to figure out beforehand how many digits the maximum ID is, I.E., if you came up with 130 commands, you need three characters sent for the ID, which allows you up to 999 commands just in case. If you only come up with 20, use two characters, that gives you 99 to play with.

omg no! Thinking of things as strings is inefficient and less flexible than the "real" way of using the binary data. If the data is in binary why turn it into strings? It's completely illogical.
http://gpwiki.org/index.php/Binary_Packet

What do you do when you need to send 100 floating point numbers?
A game server that's a "general" game server is the MIX server from http://www.synthetic-reality.com/. You might want to look at that for inspiration. The main draw-back is that, if a server doesn't know about specifics about a game, it can't enforce the specific rules of that game, and thus it opens itself up to client cheating.

enum Bool { True, False, FileNotFound };
Quote:Original post by Sirisian
Quote:Original post by deadstar
Plus, you'll be able to figure out beforehand how many digits the maximum ID is, I.E., if you came up with 130 commands, you need three characters sent for the ID, which allows you up to 999 commands just in case. If you only come up with 20, use two characters, that gives you 99 to play with.

omg no! Thinking of things as strings is inefficient and less flexible than the "real" way of using the binary data. If the data is in binary why turn it into strings? It's completely illogical.
http://gpwiki.org/index.php/Binary_Packet

What do you do when you need to send 100 floating point numbers?


Seems I've used the incorrect terminology, that's not what I meant.

It's been a long morning :P

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

This topic is closed to new replies.

Advertisement