Teen Programmers Unite  
 

 

Return to forum top

Peer to Peer base

Posted by Privateer [send private reply] at April 24, 2001, 10:55:14 AM

I have recently begun work on a peer to peer system, made in win32, which will be the base for a game that myself, and several friends are designing. I was wondering what the most efficient system would be for this, as the server running the system would be handling accounts/game managament/chat, and would need to support about 500 users.

Right now, I have a console app server, created using Winsock, and portable to BSD(which is what it will be in the end), running a loop, selecting on sockets that are available for reading, and then using a linked list to store information, as well as determine the players state(waiting for auth, chatting, playying, etc).

When a player logs in, he sends his data, and the server checks it against a file, and either sends an authentification message, or creates a new account(this works, but is quite slow when dealing with 10 - 20 logins at once). Is there any way of speeding up file access besides loading the file into memory at runtime?

Also, when a user logs in, the server sends a userlist, containing a char[20] array, and 2 ints, for EACH online user. In the max test of about 75 users, whenever several users would logon at the same time, it took a while for the server to get all of that data sent. Is there perhaps a way to speed this up?

thanks

Posted by SYN [send private reply] at April 25, 2001, 10:11:23 AM

Could you show us the exact code you use to read in the line or two of code which reads in the file? I need to see because if you're using buffered getc for example, you can dramatically speed it up by using block fwrite commands instead as well as fseek...

The only way I can think of to speed up the username send op is to trim the string for each username down to the exact length of the username, not an arbitrary length like 20. This is good for 2 reasons, first because it will often be faster (how many people even have names of 20 chars or more???) and second because it will help you to catch memory overwrites more easily. You should try avoid statically allocated arrays like this, except for quick-n-dirty testing purposes. Also, if you're using a modern day compiler, each of those ints is probably 32 bits wide, which adds up to 8 bytes just for them alone, as well as 20 bytes for username: 28 bytes, which * 75 = 2100 bytes sent *per player*! Shit!

Why don't you rather try using an Ethernet broadcast mode to send all of that once to every machine? I must admit I don't have much experience w/that stuff, but that seems like the obvious way to do it to me.

If you only need a small integer number for the 2 ints, try using unsigned chars or short unsigned ints. Those are far smaller. Also beware of C's bitpacking in structures, if you use those, as it will sometimes pad odd bytes with extra data to round the addresses off for optimization.

Posted by SYN [send private reply] at April 25, 2001, 10:12:42 AM

Oh, and if you dynamically alloc each name the name can have any length you like, with a bit of extra coding on your part to either store the length somewhere or simply check for the trailing \0 @ the end of the string during transmision.

Posted by SYN [send private reply] at April 25, 2001, 10:15:18 AM

And beware of writing servers of *ANY* kind under Windows. Windows' IP stack is very gay when it comes to things like multiple simultaneous connections transmitting data @ once. Rather start and finish the thing under a *real* server OS like FreeBSD, then port it to Windows for people w/no choice!

Posted by Setherd123 [send private reply] at April 27, 2001, 04:08:40 PM

"Windows' IP stack is very gay" <-- H0m0f0b3

"under a *real* server OS like FreeBSD" <-- very g4y

Posted by CHollman82 [send private reply] at June 14, 2001, 09:45:34 PM

Love the freestyle writing Sethie. BTW that seemed useless and uncalled for, SYN seems to know what he's talking about, and answered the question quite thouroughly. I don't think this thread needed your input.

Posted by Setherd123 [send private reply] at June 14, 2001, 10:28:13 PM

Erm, I didn't write that.

Posted by gian [send private reply] at June 15, 2001, 03:51:41 AM

Yes, I had Lordaerom do that to me once, a while ago... Not to point the finger, but... hmmmm

Posted by lordaerom [send private reply] at June 15, 2001, 09:38:12 AM

I didn't do it!

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.