Skip to main content
GameDev.net gamedev.net
🔒 Locked

TCP Book Recommendation

Started by karcieri Jun 29, 2006 at 11:36 PM 7 replies 1k views
Original Post
karcieri
karcieri
I'm trying to build a solid server core and I'm getting a lot of my questions answered but my major problem is TCP socket coding (Windows.. not unix sorry =/) I'm trying to learn how to send dynamic packet sizes, eg have a struct of a basic header and another struct that include it with additional information, over a TCP connection. If anyone knows of a good book that might explain this subject (and more!) I would appreciate it. Cheers -Kenny
hplus0603
hplus0603
Look at the implementation of packet parsing in Etwork for an example. It's a pretty simple concept, but gets complicated by the fact that you may receive half of a header in one call to recv(), and then have to wait for the other half.
enum Bool { True, False, FileNotFound };
karcieri
karcieri
Thanks for the help!

Out of all the programming I've been studying over the years, network programming seems to be the most difficult to get a handle on and find examples to build off of.

In the FAQ is says that socket sets are the best thing to use for a Client/Server game model. What is the downfall of using a TCP buffer stream? Or is it that the game should poll for user input, process, and then send out the result back to the users?
hplus0603
hplus0603
I don't quite understand your question. Explain how you think that TCP buffer streams and socket sets solve the same problem?
enum Bool { True, False, FileNotFound };
karcieri
karcieri
The two solutions I thought that were possible:

1) Create a thread for each user that has a buffer of all packets receieve by that user. Remove a packet from the buffer and process in the game state.

2) Create a FD_set to contain all the users and poll the set for activity to proicess in the game state.


... or maybe I have no idea what I'm talking about when coming to processing packets in a client/server model =(

-K
hplus0603
hplus0603
Ah, that's what you mean. We call that "a thread per socket" versus "single-threaded".

Thread-per-socket is easy to implement, and scales reasonably well to about 8 players. If you want "dozens" of players, it'll probably still work on a PC, although the overhead can be measured. If you want "hundreds" of players, thread-per-socket keels over and lies wimpering on the floor.

A single fd_set is more portable, and will work with hundreds, although you will start spending more time than you'd like in the kernel/network implementation.
enum Bool { True, False, FileNotFound };
karcieri
karcieri
any recommended reading for fd_sets besides the Etwork package? Ive been messing around with blocked sets, but I feel a basic understanding doesnt really lend itself to a very efficent server
hplus0603
hplus0603
The Forum FAQ has a lot of general socket reading pointers.
enum Bool { True, False, FileNotFound };

Topic Locked

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

Sign in to reply to this topic.