News for hackers. Stuff that matters.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by patmcguire on Monday February 24, 2014 @01:42AM (#7289422)
Always incredible to read about how problems were first solved. Things like

Lesson Two: TCP is evil, don't use TCP for a game...

Lesson Three: Use UDP...

and the like are all "of course" solutions now, but they weren't then. How do you build something fast and reliable over something slow and creaky? Who knows.

The shoulders of giants have gotten a lot taller since then.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by RyanZAG on Monday February 24, 2014 @02:08AM (#7289497)
TCP is very widely used by multiplayer gaming today. It turns out you can just tweak it a little bit and it works fine.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by nhaehnle on Monday February 24, 2014 @03:02AM (#7289612)
I can confirm this, having been mostly responsible for the network code in Widelands. We exclusively used TCP with parallel simulation (i.e., only player actions are transmitted), and it worked just fine as early as 2007 even without any special tweaks. There are two factors that matter, I believe:

First, Widelands is a real-time game but with a slow pace, so relatively high latency is easy to tolerate. Second, the internet is simply more reliable today than it was 15 years ago, especially if the bandwidth that you use is small relative to the Mb/s connections that are common today.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by exDM69 on Monday February 24, 2014 @07:08AM (#7290346)
> First, Widelands is a real-time game but with a slow pace, so relatively high latency is easy to tolerate. Second, the internet is simply more reliable today than it was 15 years ago, especially if the bandwidth that you use is small relative to the Mb/s connections that are common today.

Exactly. TCP is fine if you can tolerate 3-5 round trip times' worth of latency. RTT to the other side of the world is ~135 milliseconds at the speed of light. That's roughly one second of latency for a less than optimal network connection. Probably just fine for an RTS game or a not quite real time MMO.

It is not, however, good enough for fast paced FPS games, racing sims or (space) flight sims. They will keep on working better with UDP as long as there will be latency and packet loss in the Internet.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by willvarfar on Monday February 24, 2014 @06:49AM (#7290270)
The players were on 28K modems; it was a very different world before broadband even.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by mcguire on Monday February 24, 2014 @01:04PM (#7292286)
Did you use a server, rather than peer-to-peer communications between players?
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by nhaehnle on Monday February 24, 2014 @05:24PM (#7293831)
One of the players acted as a server, though this was actually more to avoid the headaches associated with NAT rather than for bandwidth reasons.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by pilif on Monday February 24, 2014 @07:46AM (#7290457)
Also, nowadays, there are (usually) no more slow and brittle dialup modems in place any more. A connection without packet loss is way more common these days than one with.

This makes TCP much more feasible (and sometimes necessary as getting UDP packets through various NAT routers can be difficult).

Back then, they were probably right to use UDP, but I found it funny how all the reasons they gave why TCP sucked were things their workarounds were equally bad at.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by JPKab on Monday February 24, 2014 @09:14AM (#7290806)
All of this engineering and technical analysis is wonderful and interesting, but it doesn't change the fact that Lucas Arts sold this game for a big chunk of change to my teenage self (I did farm work to earn my money) and it was a HUGE, DISAPPOINTING RIPOFF. The single player AND multi-player aspects of the game were shit. It was rushed to production by the publisher and it showed.

I realize that it was a huge technological leap for early 1997, I really do. But the product was shit and we paid good money for it.

Edit: I meant to add something. 11 months after XvT was released, Volition Software released Descent: Freespace. It was everything that XvT should have been. Nobody noticed it but whatever. (I admit I'm probably being unfair since the internet was changing so fast back then)

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by ArbitraryLimits on Monday February 24, 2014 @09:33AM (#7290937)
> I found it funny how all the reasons they gave why TCP sucked were things their workarounds were equally bad at.

I have yet to see anything designed with UDP instead of TCP that didn't end up reimplementing TCP itself, poorly.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by angersock on Monday February 24, 2014 @12:36PM (#7292089)
Problem is that you usually only want a subset of what TCP does, and sometimes the simplest/most straightforward way of getting that is a little reliability sauce over a standard UDP connection.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by voxic11 on Monday February 24, 2014 @06:12PM (#7294055)
Most games that use UDP do not reimplement TCP because data that is too old is simply not relevant to the game anymore so it is not resent. If TCP had a way to indicate messages shouldn't be delivered anymore that would be great.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by golergka on Monday February 24, 2014 @05:24PM (#7293832)
But TCP is developed for everyone, while you can develop your own custom TCP for your own task.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by nknighthb on Monday February 24, 2014 @09:21AM (#7290856)
I haven't used a dial-up modem since ~1999, and have had 7 different connections in 6 different cities on the west coast in that time. ~0.5-3% packetloss has never stopped rearing its head, especially during prime time. If you've got a magic source of packetloss-free last-mile connections, I'd love to hear about it.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by pilif on Monday February 24, 2014 @09:32AM (#7290925)
I live in switzerland and I have been using DSL and tv cable modems since 2001 and I never had packet loss (unless there was something broken on the providers end and subsequently fixed by them - this was something that lasted for maybe a day or two)
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by exDM69 on Monday February 24, 2014 @10:20AM (#7291215)
Yes, there's pretty much no packet loss in normal conditions if you measure using ping.

But in real world scenarios there are lots of reasons for packet loss, congestion being the most important. Have your little brother turn on a bit torrent client on a DSL line when you're playing counter strike and you will experience packet loss for sure.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by nextweek2 on Saturday March 08, 2014 @09:33AM (#7365255)
No, no, no.

Your understanding of TCP is wrong. Packet loss is a natural part of the process. When a link is saturated, a router should drop packets and notify the sender to slow down.

When ISPs engineer their networks to not drop packets they add larger buffers, packets wait at the last hop and instead of high speed you get high latency. Games lag at the expence of bandwidth.

Read up about buffer bloat.

Games should use UDP, as its not important if 0.5% of position updates don't get through, but it is important the get through quickly.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by prewett on Monday February 24, 2014 @03:58AM (#7289778)
What tweaks should one use?
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by laichzeit0 on Monday February 24, 2014 @08:37AM (#7290632)
The only way I know to reduce latency at the socket API level is by turning off the Nagel algorithm (TCP_NODELAY).

I'm not sure what else you can do without breaking portability or tweaking OS parameters.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by astrobe_ on Monday February 24, 2014 @12:07PM (#7291871)
... and that's the crux of the problem.

TCP is good enough for the large majority of not-too-demanding use cases. But in some corner cases it becomes more of a problem than a solution, because it is more or less a black box; one has very little control over the number of repetitions (sometimes it's even advantageous not to repeat), the repetition timings, the window sizes, etc.

In these corner-case situations you prefer UDP because you have better control on what happens. Also if you work with some obscure TCP/IP stack implementations you wouldn't bet your life on (that happens in the embedded world), and that you don't feel like debugging, or if datagrams are more convenient than streams for your app(sometimes new programmers are surprised to receive one packet when they sent two - or the other way round), UDP doesn't look that bad at all.

I read once a rant that argued half-jokingly that TCP is useless, because in the end the services it offers are redone at application level. Repetition? most applications do retry a failed operation? Acknowledgement? Ditto. Encryption? Same.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by mcguire on Monday February 24, 2014 @01:13PM (#7292344)
There are, of course, a [heap; I originally wrote "stack"] of reasonably standard protocols other than TCP and UDP with behavior that may be more appropriate for games; many are based on top of UDP. RDP comes to mind, although it's not much of a protocol itself.

> I read once a rant that argued half-jokingly that TCP is useless, because in the end the services it offers are redone at application level.

Half-jokingly? Essentially all services provided at "layers" below the application are, at best, performance optimizations. See the End-to-end argument.[1]

[1] http://en.wikipedia.org/wiki/End-to-end_principle (or the Saltzer/Reed/Clark paper; it's very good: http://web.mit.edu/Saltzer/www/publications/endtoend/endtoen...)

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by mzs on Monday February 24, 2014 @01:51PM (#7292619)
Also setsockopt TCP_MAXSEG = 536 and do small sends with your own ID numbers. When one IP fragment from a fragmented packet goes missing everything stops and then everything from that packet is resent. On lossy networks that bigger packet has a bigger chance of again having a missing fragment so there will be an additional delay.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by stoptalkingshit on Monday February 24, 2014 @02:33AM (#7289552)
It works just fine.. for non-realtime games (and has been widely used for such games since forever). I've done the tests - you cannot just "tweak" it, and even if you could you'd be relying on the networking stack to do something it's not intended to do.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by forrestthewoods on Monday February 24, 2014 @02:37AM (#7289559)
You might be surprised. World of Warcraft and Guild Wars 2 are both TCP. It's pretty common for MMOs. It can also work well for some types of RTS games where the added latency isn't a major issue.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by lucian1900 on Monday February 24, 2014 @05:14AM (#7290001)
They're not real-time, though, in the sense that a delayed message is as good as no message. The tolerance is high enough that a few delays usually don't affect gameplay.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by RyanZAG on Monday February 24, 2014 @02:40AM (#7289563)
All flash games use TCP (as you can't use UDP in flash). There are many realtime flash games. Many MMORPGs use TCP for compatibility reasons: they are very much real-time, especially something like PVP in world of warcraft, etc. Guild Wars also uses TCP and is very much a 'twitch' based realtime game as well.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by shultays on Monday February 24, 2014 @04:07AM (#7289805)
PVP in mmos are hardly real time.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by RyanZAG on Monday February 24, 2014 @04:44AM (#7289913)
Spell interruption in warcraft? Also first youtube video for 'guild wars 2 pvp' : https://www.youtube.com/watch?feature=player_detailpage&v=KR...

Looks like real time to me.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by PeterisP on Monday February 24, 2014 @08:12AM (#7290539)
WoW is the type of game where it can reatroactively change things when data is received and have it mostly be unnoticeable.

Your spell interruption example illustrates it perfectly - spells can be interrupted if the interrupt is within the 1-2s cast time of the spell. It's adjudicated on server side, where the server knows the spellcast start and sends feedback on the spell results (including if any interrupts happened). If there is minimal delay then it works without being noticed; however when I had significant packet loss, then the spellcasting would 'end' for me only after the response (including check if it was interrupted) was received, and it could be multiple seconds later.

The point is, that WoW can mostly function if the orders and feedback are received with delays, since if some opponent in reality(server) is somewhere else than I see, then it usually doesn't change anything - but for a rapid movement FPS game, that would change hits to misses which is the core of that game.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by shultays on Monday February 24, 2014 @06:27AM (#7290213)
Didn't play much wow but aren't spell cast times like 2-3 secs in wow? Even with a 0.5-1 sec delay, it would be playable. Never played guild wars

Maybe my definition of real time is incorrect. But you don't point and click in MMOs generally, it is all aoe spells or targetted abilities. There are big margins of time or spell aoe to overcome delays of network packets.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by Glide on Monday February 24, 2014 @10:53AM (#7291426)
1.5 second cast times with abilities to push that down to around 1.0s. A lot of the interrupts are off the global cooldown in order for players to use spell interrupts effectively.

.5 - 1 seconds of delay may not seem like much, but it actually adds up to be quite significant because of the global cooldown would also be enforce client side and so a player with higher delay would have done fewer actions in the same amount of time.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by Luyt on Monday February 24, 2014 @06:50AM (#7290274)
Spells vary in casting time. Many spells are instant.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by m_mueller on Monday February 24, 2014 @08:50AM (#7290682)
- and the instant ones aren't interruptible I guess?

People, I don't even get what you're discussing here. That TCP should be fine for any game's network code because it works for WoW?

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by DonPellegrino on Monday February 24, 2014 @09:34AM (#7290942)
I disagree. Even back in 2005-2006 - almost a decade ago!, in Guild Wars pvp, it was possible to interrupt a 1 second spell with a 1/4 second one, leaving you with 750ms for human reaction time and latency.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by stoptalkingshit on Monday February 24, 2014 @03:02PM (#7293076)
World of Warcraft is not a "twitch" game. Ever multi-screened it? Why make all this stuff up? This may surprise you, but Flash games don't set the standard for quality network code.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by gcp on Monday February 24, 2014 @03:46AM (#7289746)
How do you build something fast and reliable over something slow and creaky? Who knows

You use TCP, which they already had.

The article describes TCP as evil, but then they go on to reimplement TCP over UDP in a way more inefficient manner, not realizing their problems with TCP were problems with the internet. They'll hardly have been the first ones to do so, either.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by exDM69 on Monday February 24, 2014 @06:53AM (#7290290)
> The article describes TCP as evil, but then they go on to reimplement TCP over UDP in a way more inefficient manner, not realizing their problems with TCP were problems with the internet.

Almost every real-time game out there "re-implements" parts of TCP over UDP because the mechanisms that TCP use are unsuitable for real time communication.

If a packet goes lost over a 150 ms latency (something modern game engines manage gracefully), the server will receive a resent packet that contains information from 450 ms ago. Additionally a packet going lost with TCP will inhibit the delivery of successfully received packets that were sent after the one gone missing. Re-sending an old packet (like TCP does) is worse than not receiving the packet at all in multi player gaming.

You do need (semi-) reliable delivery, connection management and flow control over UDP but implemented differently than TCP. When a packet goes lost, you send the up-to-date information instead, not what was relevant 300 ms ago.

TCP is a wonderful protocol but absolutely useless for multi player gaming. Everyone who has been writing netcode for real-time games (there are exceptions like RTS, MMORPG, etc) knows that.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by louiz on Monday February 24, 2014 @11:49AM (#7291736)
I think “real-time” does not mean what you think it means.

I’ve read a lot of things like “TCP is not suitable for real-time online games”, in this thread, where the author of this sentence excludes RTS, MMORPG, etc. As if these were not real-time games.

According to http://en.wikipedia.org/wiki/Real-time_game#Real-time (and also the fact the RTS means real-time strategy), any game that is not turn based is a real-time game.

It’s not just you, but I had to choose one of the posts in this thread for my response. Saying “TCP is a wonderful protocol but absolutely useless for multi player gaming” is just plain wrong. A lot of online, real-time games are using TCP. Saying that TCP is useless for multi player gaming is really misleading and I’m tired of reading this. There are a lot of valid reason to choose TCP over UDP (for example the fact that your game doesn’t require any round-trip to be shorter than, say, 500ms, because that’s how the engine works). Of course, TCP would not really be suitable for an FPS like quake, but that’s only one case of real-time game, there are a lot of different kind of games, for which TCP is the best choice.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by exDM69 on Monday February 24, 2014 @12:37PM (#7292092)
> I think “real-time” does not mean what you think it means.

There are various definitions of "real-time" and we should not make this an argument about semantics. I meant real-time in the sense of "a soft real time software system" or the "Quake" sense of the word.

http://en.wikipedia.org/wiki/Real-time_computing#Criteria_fo...

In other words, "real-time" in the sense that missing deadlines will mean that the quality of service is degraded. Deadlines here mean delivering the packets in time for the next simulation timestep.

Yes, TCP can be successfully used in games classified as "real time" as opposed to turn based, such as RTS games or MMORPGs. But when analyzing it them from a software standpoint, they might be just very fast turn based games.

Here's another interesting piece about networking multiplayer games, this time in an RTS game (Age of Empires): http://www.gamasutra.com/view/feature/3094/1500_archers_on_a...

The solution they used was essentially a 15 frames per second lock step loop. It looks like real time to the player but from a software standpoint it really isn't.

You and I agree on everything except the definition of "real-time". There are applications where TCP works well and applications where UDP is better. I'm sorry if my words were a bit overgeneralized and it annoys you.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by louiz on Monday February 24, 2014 @03:56PM (#7293380)
> In other words, "real-time" in the sense that missing deadlines will mean that the quality of service is degraded. Deadlines here mean delivering the packets in time for the next simulation timestep.

Yeah, that’s what happens in most RTS, if the feedback for the action you sent doesn’t come back before Xms, then the game pauses and waits (for example Starcraft 2 does that).

And I know the lock step mechanism used in some RTS, I’m implementing one myself. But I don’t see how it makes it non-real-time. If quake or teeworlds associates a network packet (containing a player-position) with a frame, does that make it really-fast turn-based game (with turns being frames, or ticks, or what you want to call them)?

That being said,

> You and I agree on everything except the definition of "real-time".

No, the “real-time” word is really not that important to me, I mostly disagree with you saying “TCP is […] useless for multi player gaming.”

RTS, or MMORPG, or turn-based tactical RPG, or card games are not “some exceptions”. They probably even represent a huge proportion of the multiplayer games out there. I now understand that you were talking about “fast-paced action games like quake or the likes”, but that really didn’t sound like it.

> I'm sorry if my words were a bit overgeneralized and it annoys you.

This is not just you, I’ve seen a lot of these “— TCP sucks for all online game purposes! — but what about all these cases were it’s fine? — Oh, I was obviously talking about those other cases”

But that’s ok, I’ve made my point public instead of grumbling in my head, now I’m fine and we can move on. :)

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by exDM69 on Tuesday February 25, 2014 @05:47AM (#7296813)
> > In other words, "real-time" in the sense that missing deadlines will mean that the quality of service is degraded. Deadlines here mean delivering the packets in time for the next simulation timestep.

> Yeah, that’s what happens in most RTS, if the feedback for the action you sent doesn’t come back before Xms, then the game pauses and waits (for example Starcraft 2 does that).

To elaborate on this further, I would not consider Starcraft 2 a real time system, because it can stop the world and wait. It is annoying when it starts lagging but produces the "correct" results anyway.

This is not the case for simulators that deal with "continuous" physics updates. All clients are simulating the world in parallel and no one has the authority to stop everything. If lag gets significant, the results will become more and more incorrect and the view of the world that the clients have will diverge more. There's always some inaccuracy but that is tolerable to some degree.

This is by no means the only or necessarily the correct definition of real time but that's where I draw the distinction when it comes to multiplayer games. Someone might not agree with me on this one.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by mcguire on Monday February 24, 2014 @01:20PM (#7292396)
Could you provide an example of a real-time game?
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by exDM69 on Monday February 24, 2014 @04:15PM (#7293457)
For some definition of real-time, a racing simulator is real-time because it will produce incorrect results (with catastrophic consequences) if there is too much latency. An RTS like Age of Empires is not because it will only lag annoyingly but still produce correct results.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by hnisnotreddit on Monday February 24, 2014 @05:08PM (#7293750)
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by tlarkworthy on Monday February 24, 2014 @05:25AM (#7290038)
No. They implemented forward error correction, which is a proper thing not supported by TCP.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by waps on Monday February 24, 2014 @06:23AM (#7290204)
The article even contains an explanation why TCP does not, and NEVER should, include forward error correction :

> Our simple re-sending mechanism just didn’t perform well enough under these conditions. It was quite common for a re-sent packet to be dropped, and we saw several cases where the original packet and 4 or 5 re-sends of that packet would all be dropped. We were re-sending so many packets, we were starting to exceed the bandwidth of the modem, and then the latency would start to climb, and all hell would break loose.

(then they implemented a -very bad- form of forward error correction in their packets to almost never need retransmissions)

This effectively ignores available bandwidth, and it worked because they were only using tiny amounts of bandwidth, so cheating helped them in this case, without ill effects. It is a dangerous game however. The problem is one of unfairness. If you implement your connections with forward error correction you will have an advantage over others, as you will not follow congestion signals while others do.

And then this happens :

http://en.wikipedia.org/wiki/Congestive_collapse#Congestive_...

TLDR: massive traffic on nearly every link in the network. Effective throughput almost nonexistent. You know, like being stuck on comcast.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by tlarkworthy on Monday February 24, 2014 @06:32AM (#7290230)
I am not suggesting Forward Error correction is a good idea on TCP. They put UDP and forward error correction together which is a good idea (see video/audio streaming over internet). The parent seemed to think they had reimplemented TCP badly, which they didn't, they implemented quite a different protocol which utilised forward error correction which was a good idea and something they would not have been able to do by building on vanilla TCP.

So their prototcol probably ended up messier than it should of been but they were pioneers fixing problems as they cropped up so that's understandable.

Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by zura on Monday February 24, 2014 @04:27AM (#7289855)
There also was a quite interesting protocol T/TCP - which was something between TCP and UDP.
Re:The Internet Sucks: Or, What I Learned Coding X-Wing vs. ... by TheZenPsycho on Monday February 24, 2014 @04:46AM (#7289917)
so how would you have solved it? your explanation here is pretty unsatisfying since they did use TCP, and it didn't work.