Problem with Lag

I’m currently working on an MORPG by myself coding from the ground up. I thought I had the basics of networking down, but when I change the IP from local host to the real IP there’s serious lag issues.

Players can move around and see each other, but they skip horribly. This leads me to believe the way I’m doing the networking is way off. Currently the server is setup to broadcast player positions 33 times a second, and the client is set to update the screen and inform the server of it’s position 33 times a second. I’m using output streams and sending lines such as “PXY 300 200” to the server as a means of updating positions.

How exactly should I go about fixing this skipping issue? Is it just completely horrible networking or is it the way I’m sending messages back and forth as strings?

Any help would be much appreciated, and source can be provided if that would help figure out the problem.

When the client receives “PXY 300 200” does it blindly set the location to 300, 200 or is there an attempt to smooth this movement?

There is quite a few threads here on the topic. Basically synced simulation is the way to go, more or less.

However you should be careful to define exactly what you need. If you don’t expect more that say ~16 players at once, and if you don’t have a massive game state, then something like what quake 3 does is the easiest way (again there are many threads, use google rather than the forum search).

Otherwise minecraft is doing very well, with massive numbers of people.

Oh by the way, 33 times a second is 30ms. Yet a 50ms ping is pretty common even with broadband, so you must consider “synchronization” very carefully.

Hmm, I never thought of that zoto. It does just blindly set it, but I thought with tcp it make’s sure it receives every message in order so if it’s receiving every new position shouldn’t it still look smooth? (it should be receiving every 5 pixel movement, and the changes in frames which is how the local player moves… every 5 pixels and updated frames)

Well I doubt this game is ever gonna become too massive so it will probably be around 20 people at the most. And thanks for the suggestion about the ping, forgot about that too. I’ll work on that.

Thanks for the help

are you using tcp or udp?

if youre using tcp, its a better idea to collapse 10 (or so) move packets into a single packet and send one of those every second instead of a seperate move every 100ms. this way, the movement wont be held up as much as if you sent 10 move packets a second (because of tcp, if packet #1 fails to send, the client will send it again, and the server will need to wait for #1 to arrive again before it can process #2-#10.)

if youre using udp, sending 10 small move packets per second should be fine, as a lost packet shouldnt affect anything.

As stated above, you should also use some sort of interpolation (and perhaps extrapolation) to smooth out the movement.

  • David

don’t forget that UDP can also change the order of packets, so you need to handle that as well as dropped packets.

Alright thanks for all the help, sorry bout the late reply I’ve been on vacation.

I’ve summed it up to making these changes:

  • instead of transporting strings back and forth, I’m going to send objects between the client and server. Idk if its faster but it helps with organization
  • condense 10 move packets into 1, and send those on a separate timer.
  • fix up a graphical transition between old and new positions of distributed sprites.

I’ll get to work on this when I can and hopefully the results will mean I don’t have to ask for more help ha. Thanks again