It is currently Tue May 21, 2013 2:44 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Game networking
PostPosted: Fri Jun 18, 2010 3:25 pm 
Offline
New User
New User

Joined: Fri Jun 11, 2010 2:51 pm
Posts: 3
Hi there,

I got some problems with creating a multiplayer game. My server creates a thread for every connected client which waits until a packet is received and then sends it to all of the other clients. I also added ping. When doing nothing, I got a ping of ~90ms (with a friend hosting the server) but when moving (creating some traffic), ping raises to about 400ms.
I'm only submitting when a key is pressed or released and some control packets every second so traffic should be almost nothing. Then I thought the server would be too slow to send the packets in time but the one who's hosting the server has always a ping of 0ms but he would be affected by that too. I don't have any idea about what's wrong here, so I would be really happy if someone could help me understanding all that networking stuff because it's hard to debug and very frustrating..
I can post or upload code if needed but I think it would be better if someone could explain me how all this is working instead of just correcting my code..


Top
 Profile  
 
 Post subject: Re: Game networking
PostPosted: Fri Jun 18, 2010 6:06 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2010 11:36 pm
Posts: 103
Hi,

it is hard to say what is going wrong, because you do not seem to use the standard implementation of the network commands and you dont give any further information about your implementation.

So i just can guess, but it seems for me, that you use TCP sockets (because of the different sockets in the threads), which are based on streams and not on packets. So, it is possible that the operating system combines packages, which you sent after another, to one single packet.
Could it be possible, that you do not parse the received packets correct, if you receive different packages in the same memory block? The idea would be, that the server receives MOVE + PING, parses the Move but misses the ping. Later, the client would interpretate a different PING Answer as a reply to a PING request which was not answered. This would result in a big Ping?

DarkPlayer

_________________
My blog: http://fds-team.de/cms/


Top
 Profile  
 
 Post subject: Re: Game networking
PostPosted: Fri Jun 18, 2010 7:08 pm 
Offline
New User
New User

Joined: Fri Jun 11, 2010 2:51 pm
Posts: 3
Ok, I must admit I'm not as good in programming as you think, I don't know anything about using an other implementation and about TCP sockets. I'm using the standard network library and I'm only talking of "packets" because I always send blocks of 10 bytes (+1 added at server for client identification). I want to learn all that stuff, that's why I posted here..
I think those "packets" are received correctly, the other players don't move smooth anymore etc
So I did something wrong because of my lack of knowledge about threads and networking, I want to learn more so I can do better :)


Top
 Profile  
 
 Post subject: Re: Game networking
PostPosted: Fri Jun 18, 2010 7:22 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2010 11:36 pm
Posts: 103
Hi,

first, you should not use Threads for every client, they are not necessary for the standard network implementation and would only mess up everything. The second thing ist, that if you use tcp, there are no "packets". Lets say you send 10 bytes, than it can happen that the server receives 1 byte, 5 byte and 4 bytes. You have to save all the received data till you got a full package and if you receive 15 bytes, you also received 5 bytes of the next package. And you don't need a byte for client identification, you can identify them by their connection ids. Otherwise a player could just fake his ID and control another Player :mrgreen:

DarkPlayer

_________________
My blog: http://fds-team.de/cms/


Top
 Profile  
 
 Post subject: Re: Game networking
PostPosted: Fri Jun 18, 2010 7:48 pm 
Offline
New User
New User

Joined: Fri Jun 11, 2010 2:51 pm
Posts: 3
Yeah, I'm already sending and receiving until my "package" is complete (checking how many bytes are actually received/sent, delay and so on) and the client identification is added at the server (in use of the connection ids). The threads, I will try without them..


Top
 Profile  
 
 Post subject: Re: Game networking
PostPosted: Sun Jun 20, 2010 1:31 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:51 pm
Posts: 2715
Location: Portugal, Lisbon
I've build quite a number of servers in purebasic, and i've had no problem connecting up to 3000 clients.

It uses 3 threads and linked lists.

I will not be posting code here, because it's too long or under NDA, but here's the logic i use:

Image

I hope it helps!

_________________
Software: http://xipa.org
Elevator Maintenance: http://central-elevadores.pt
Good web hosting!


Top
 Profile  
 
 Post subject: Re: Game networking
PostPosted: Mon Jun 28, 2010 12:37 pm 
Offline
New User
New User

Joined: Mon Jun 28, 2010 12:00 pm
Posts: 1
Try to avoid the tcp sockets. Usually UDP sockets promise better performance for games and basically they use less system resources. And btw UDP really works with packets!


Top
 Profile  
 
 Post subject: Re: Game networking
PostPosted: Mon Nov 14, 2011 2:24 pm 
Offline
User
User
User avatar

Joined: Fri Mar 04, 2005 7:46 pm
Posts: 40
Location: argentina
examples :D


Top
 Profile  
 
 Post subject: Re: Game networking
PostPosted: Sun Dec 11, 2011 10:24 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:50 am
Posts: 454
Location: Bradenton, FL
First of all, here is a good overview of TCP vs. UDP:

http://codeidol.com/unix/unix-network-programming/Advanced-UDP-Sockets/When-to-Use-UDP-Instead-of-TCP/

Second, I wholeheartedly disagree about using threads. I would recommend threads when serving multiple clients.

Third, I would only use UDP if running over a LAN, as too many things can go wrong over a WAN. That is unless the data sent is not critical in nature.

What you could do to cut down on the overhead of TCP is to leave the socket open once connected. That means you would have to write code to wait for data on each socket, and that's where separate threads really help. If that is something you might want to do and would like some help, just let me know. I'd be glad to assist you. The folks on this board have really helped me!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye