Jump to content

Some notes regarding SC2 networking


Recommended Posts

http://www.teamliquid.net/forum/viewmessage.php?topic_id=117158

Since I see a lot of misinformation flying around, here's some brief information about SC2 and how its networking works.

UPDATE: Note that when I refer to latency in this post, I'm meaning network latency over the wire. Starcraft 2 includes a built-in command buffer that also adds input latency to smooth out and jittering or higher ping players - no amount of tweaking will reduce or alter that.

Architecture

Stacraft 2 games run using a server, similar to HoN - not peer to peer as the original BW does. This means that Blizzard is the one hosting the games, not you (note: custom games were not tested). The protocol is TCP, not UDP. I'm unsure why Blizzard decided to go with TCP/IP, since latency is generally worse over TCP especially with regard to lost packets. Perhaps they didn't want to deal with fragmentation or NAT issues?

"Drop hacks" / Lag

Since other players also connect to Blizzard's server, not you, there is no way to be "drop hacked" in SC2. Drop hacking involves terminating the connection to the other player via some means - trivial in BW since both players are connected to each other - desynchronize the connection and you get a drop. However in SC2, since you are only connected to Blizzard's server, not the other player, the most you can do is disconnect yourself from the server, causing you to drop. Since the server knows who disconnected, it can award the win to the remaining player.

Note that this does not preclude any bugs in SC2 that might allow someone to purposefully cause a drop condition by sending malformed packets that crash the server (thus dropping everyone), but given the server architecture, drop hacking should not be an issue in SC2 provided the servers are reliable and well-coded.

You may notice there is still the "Waiting for players" screen. Rather than allow the server to continue if one player is lagging, it pauses the game for everyone. This was done out of fairness I imagine, since if someone is lagging it would not be fair for them to have to engage the other players army. Technically there is no reason why the game can't keep going similar to how HoN handles latency where only the player lagging experiences any lag. In theory this should allow a large number of spectators to be in a game without impacting the latency for the players - if a spectator lags, who cares?

Port Forwarding

Since Starcraft 2 does not use peer to peer connections, you do not need to open any ports to play nor will doing so "improve" your connection. You connect to Blizzard's server, much like you connect to teamliquid.net every time you click a link - you do not need to open ports for outgoing connections.

Map Hacking

Please keep in mind this is not a thread to discuss map hacking in, just some technical commentary. As some people have argued, since SC2 uses a server, it should be possible for the server to eliminate map hacking by only sending unit data for what a player can currently see. Theoretically, this could work - however as many have pointed out, SC2 is a lot more complex than other games such as HoN that do this - in HoN, there is a very small amount of units you have to consider, with only a few of those (heroes) having any particular state. With SC2, there can be hundreds of units, each in many states. If someone moves into your fog of war with hundreds of units that your game doesn't know about, that will result in a large amount of data required to be sent to your client. TCP doesn't burst particularly well, and if one of those packets in the burst is lost, you have a significant delay. There is also spells such as Scan that reveal part of the map immediately on clicking, which the server has no way to predict you using.

While it is technically possible to reduce map hacking with some clever coding and possibly imperceptible latency compromises, this was not done. The technical requirements for such impose a great deal on the latency of the game, and for an RTS latency is extremely important. Which brings me on to...

Improving Latency

As I've mentioned, SC2 uses TCP. TCP is designed for data transfer with latency as a secondary consideration to bandwidth, so isn't really ideal for real-time games. Almost every FPS game in existence uses UDP for this reason. TCP requires reliable delivery - if a packet is lost, it has to be retransmitted, stalling the rest of the data while this happens. There is a small tweak you can make to improve TCP responsiveness for gaming.

Change TcpAckFrequency to 1:

How

Run registry editor (Start, Run, regedit) and navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces. You will see a list of random looking keys, find the one that has the "IPAddress" value that matches your current IP. Right click on the right side and go New -> DWORD. Call it TcpAckFrequency with a value of 1.

Why this works

Usually TCP delays sending acknowledgments of received data until either more data has been received OR a timeout period elapses. This timeout period may be because the sending side is waiting for the ack before sending more data. By setting TcpAckFrequency to 1, you send an acknowledgment immediately rather than waiting, preventing miniature "stalls" in the data stream. Note that this WILL reduce your bandwidth, as you will be sending more ack packets, thus using more network resources.

Things that MIGHT help

If you use ADSL, your connection may use interleaving which is a method of error resistance that adds latency to your connection. Look in your ADSL modem settings for an option to turn it off. Note that this may increase the chances of line noise affecting your connection, so it might be required to be on. You may need to contact your ISP as it may be something controlled on their side, but don't expect them to be too accommodating.

Wired vs wireless: A properly configured wireless network should have minimal latency, however if you are in a crowded area with obstructions and other 2.4 GHz noise, the latency caused by retransmissions might add up and cause issues. Try pinging your router - your latency should be 1-2ms at most. If not, try a wired connection while gaming.

If you have a low quality wireless card (common in cheap desktop / laptops), you may experience random periods of lag while it switches frequencies for background scanning (used for roaming between access points). You can turn off background scans with a tool such as WlanOptimizer (Vista / 7 only).

Tweaking your RWIN (Windows XP only) may help - see any number of guides online regarding this.

Things that will NOT help

There is a huge amount of useless information on the Internet that offers supposedly improved performance. The following will NOT improve your network quality at all: Opening your ports. Changing "TCPNoDelay" registry setting. Changing "NetworkThrottlingIndex" registry setting. Changing "TcpDelAckTicks" registry setting. Disabling "QoS Packet Scheduler". In fact, very few Last edit: 2010-03-25 08:17:27

registry tweaks will help - there's usually a good reason defaults are the defaults.

koga mrzi da cita sve, nek pogleda deo 'Improving Latency'

The thing's hollow — it goes on forever — and — oh my God — it's full of stars!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...