Simulating Network Lag

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Simulating Network Lag

Post by Lap »

Any thoughts on the best way to go about testing networking under varying conditions (packet loss, latency, etc.)?

I'm not finding any good external programs to help out.
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Simulating Network Lag

Post by josefnpat »

The easiest way to simulate lag is to put a sleep in the server before responding. I suppose you could also do something along these lines:

Code: Select all

require "socket"

function sleep(sec)
    socket.select(nil, nil, sec)
end

function handle_data(data)
  sleep(0.120) -- 120 ms
  if math.random(1,10)>1 then
    -- properly handle the data
  else
    -- haha, packet loss!
end
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: Simulating Network Lag

Post by Lap »

I'm trying to figure out what else I might be missing by simulating it only within Love.

I guess I'd miss potential problems with testing packets of different sizes, as I've seen large ones get dropped before....maybe. So far this is the most difficult part of networking, as I never have problems with LAN's, but there have been plenty of bugs reported in the wild.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Simulating Network Lag

Post by Boolsheet »

There are all kind of fun things you have to look out for. As an example, here's a quote from the luasocket reference about udpsocket:receive.
If size is omitted, the maximum datagram size is used (which is currently limited by the implementation to 8192 bytes).
Linux has some tools to simulate stuff like that, but I forgot the name. :(
Shallow indentations.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Simulating Network Lag

Post by bartbes »

And the worst part isn't fitting stuff in 8192 bytes, it's that what's sent with multiple send() calls can be received with one receive() call.
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: Simulating Network Lag

Post by ljdp »

If you've got OSX Lion and have installed Xcode then you already have a nice utility app called network link conditioner, I've been using it to test my RTS game.
It let's you change your bandwith, packet loss and latency.

http://joemiller.me/2011/07/25/network- ... -4-1-lion/
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 84 guests