6 ms·
I'm the guy that made Agar.io, Diep.io and a few smaller games. I analyzed the possibility of using WebRTC in my games several times so far, but it seems that r
by Matheus28 10y ago
I'm the guy that made Agar.io, Diep.io and a few smaller games. I analyzed the possibility of using WebRTC in my games several times so far, but it seems that right now, it's still hard to use in a server-client architecture. You need to bring this [1] behemoth and all of its dependencies to your project dependencies on the server side, even though you only care about a tiny bit of it (unreliable data channels). It's unlikely that people will start using it until there is an easy stripped-down version that only deals with data channels.
[1] https://chromium.googlesource.com/external/webrtc https://chromium.googlesource.com/external/webrtc
- pthatcherg 10y agoHi, I'm a member of the WebRTC team at Google, and I wrote a lot of the data channel and network code that's part of that behemoth. I'm glad you got this to work :). I've always hoped someone would do exactly what you've done (use the data channel code on a server to do low-latency client<->server communication). We're aware of the difficulty and are actively working on making it easier to work with just he components you need for data channels (ICE, DTLS, and SCTP). It might take a while, but it's one of our goals.
- shazow 10y agoI've been trying to find some numbers on what kind of performance characteristics for using WebRTC unreliable datachannels (compared to the spectrum between pure UDP vs WebSockets). Do you know of any such comparisons? Or any intuition on the matter?
- comboy 10y agoWhere does the low latency in WebRTC come from? Is it just packet ordering in TCP or is there something more to it?
- Franciscouzo 10y agoYou can't do packet reordering on top of TCP as it is already ordered, RTCDataChannel uses SCTP instead.
- pthatcherg 10y agoYou can receive data messages our of order. That's all there is to it. If you could receive TCP out of order, you could just use TCP.
- gravypod 10y agoIs there a way to specifiy ordering on specific packet types?
- oneweekwonder 10y agoFrom the Article: Because SCTP is configurable, we can open multiple data channels with different settings, which saves us tons of work! Typically we have: an unreliable and unordered data channel for game state data and user inputs a reliable and ordered data channel for chat messages, scores and deaths
- manquer 10y agoAlso WebRTC is inherently p2p . So you can connect directly to the other peer without server getting involved expect for connection (STUN and TURN). Basically message via the LAN even. Latency improves in many scenarios.
- banachtarski 10y agoLatency has very little to do with the p2p aspect. In a client-server setting, the use of RTP/SCTP to communicate payloads between two clients would have significantly less latency than, say, a P2P TCP connection.
- saurik 10y ago> I'm glad you got this to work :). Matheus28: Did you actually get it to work or did you give up? (pthathcerg: The comment only claims they "analyzed the possibility".)
- Matheus28 10y agoI've played with a few simple examples but didn't integrate it into any games, see https://news.ycombinator.com/item?id=13267248 https://news.ycombinator.com/item?id=13267248
- Matheus28 10y agoHey, I think you misread my comment, I haven't actually implemented it into any of my games. I've played with it for a bit but haven't gotten around actually adding it to any games. Sorry! But yeah, I really hope it becomes easier to integrate, as right now that's the biggest barrier into putting it into my custom written C++ server that I use for all my games. They already support UDP-only communication for desktop and mobile builds and bringing it to web would make the experience a lot better. Thank you!
- pthatcherg 10y agoIndeed, I misread your comment. Well, hopefully in the future how I read the comment will be correct. I don't think it would be that hard to write a data-channel-only server using BoringSSL and usrsctplib. See a comment of mine further down on the page of how you could do that. Or you can just wait until we have our code refactored :).
- z3t4 10y agoUsing WebRTC for communicating game state seems like a hack. WebRTC is too complexed with many parts. I try to get into it every year or so but I don't even get the demos to work. Then compare to Websockets that are well supported and very easy to use, with fall-back libraries such as sockjs. If possible I think it would be a good idea to break up the different parts of WebRTC so that they can work independently of each other. The abstractions are also a bit leaky, as you need to know about the underlaying layer to use it. Another approach would be having a low level API witch might be easier to implement in the browser, and then count on libraries to make good abstractions.
- pjmlp 10y agoEverything on web development feels like an hack.
- z3t4 10y agoIve built some multiplyer real time web game prototypes using websockets with sockjs fallback and canvas 2d context. Its very fun and productive. You dont have to know opengl or tcp ip and it works everywhere, even on a 5 year old Nokia.
- groovy2shoes 10y agoOh, how I wish I could upvote this 100 times. Nay, 1000! It was already bad enough 10ish years ago when it was a comparatively small pile of hacks, and there was hope that something could be done about it. But now? It's an enormous pile of hack upon hack. Full stack engineer? More like full hack engineer! The main reason I worry about losing my job or moving to a new location is that web development jobs are a dime a dozen nowadays, while more traditional development is seeming less and less relevant. As much as I hate C++, I'll stick with it over the monstrosity that is Web 2.x. [Insert the usual complaints about shitty languages, tooling, and gazillions of frameworks / reinvented wheels here.]
- z3t4 10y agoI can relate as I've been a web developer for 18 years and before that I did some qBASIC. Some aspects of web development have been stable for over ten years and feels like a foundation. Everything with computers is a "hack" though, the transistor is a hack, then everything on top of it is a hack. It's only when things get stable and has a tight abstraction things starts feeling non-hacky. But when something is stable (aka perfect) it no longer evolves and starts to get old. So you either use old stuff that worked 10 years ago and will work many years forward, or just accept that the bleeding edge technology you use today might be a bleeding mess tomorrow. One thing I like about computers and programming is that it's all created by humans. I tried go into physics and biology but once you go deep nothing really makes any sense, it's all random. With programming there's always, most of the time, reason behind design decisions.
- Matthias247 10y agoI also played with the idea of using WebRTC data channels for client server applications. From a system design perspective it looks good, since it can provide lots of concurrent flow controlled streams (like HTTP/2) with a potentially lower latency. However from the pure engineering side things don't look so great for the reasons Matheus28 already mentioned: WebRTC (even data channels only) is a big stack of massive complexity. It's not something you want to implement or understand fully on your own within a reasonable amount of time (like you could do with WebSockets). The most reasonable way to get WebRTC support seems like integrating Googles native WebRTC library. However one downside is that it's a big dependency with which a lot of people might be uncomfortable bringing in (although you say you are working on making it smaller). The other downside is that it's not only big but a native dependency, which I and other people want to avoid wherever possible in non C/C++ land. The alternative solution would be to develop a pure Go/.NET core/Java/etc. WebRTC data channel solution. However for this most of the required subcomponents are missing. Imho neither of those even support the required DTLS encryption in the (extended) standard libraries, and there are also no libraries for SCTP on top of UDP around. Therefore getting this to work is a serious effort, and anybody who approaches it must ask himself if the effort is justified or if Websockets and HTTP streaming are not good enough. For the latter one the performance might even reach WebRTC data channel performance if QUIC gets standardized and widely deployed. I think the situation might be different if WebRTC data channels would only have standardized a UDP or possibly encrypted UDP. Anybody who would have needed it could still be able to implement streams and multiplexing on top of it on server and client(JS) side. The current solution provides a nicer out of the box API, but supporting it outside of the browser is hard.
- Matheus28 10y agoI agree completely. I feel what is needed is an UDP version of WebSockets. That's all I wish we had.
- bcjordan 10y agoWhat do you do currently instead?
- Matheus28 10y agoJust WebSockets in a C++ server. I have my own implementation that I wrote from the scratch because when I started µWS [1] didn't even exist yet. I recommend their implementation for anyone planning on implementing a websocket server in C++. [1] https://github.com/uWebSockets/uWebSockets https://github.com/uWebSockets/uWebSockets
- comboy 10y agoCare to share a bit about technical side of agar.io? I've played it a bit (yeah right, a bit..) and I've been wondering how did you manage to make it so smooth without also introducing conflicts between clients (I mean e.g. on my side B ate A but somebody else sees C eating A). There is lag sometimes but I've never encountered "glitching" where position calculated locally would have to be visibly adjusted to what came from the server. Also if it's not a secret what backend did you use to handle so many concurrent connections and how many were you able to keep per box?
- Matheus28 10y agoAll my games use a server-client architecture. It's a custom written WebSocket implementation, see https://news.ycombinator.com/item?id=13267261 https://news.ycombinator.com/item?id=13267261 I think Agar.io has around 190 players per server. Diep.io has around 72.
- comboy 10y agoSo basically cell won't be eaten/exploded by virus until server says so? I would have thought that would be perceived as too slow. Per server you mean like in a game room or is one game room equal to one linux box? If so, I guess then that handling the game logic was the bottleneck, not the number of concurrent connections? Also, congrats on the success and making some really cool games.
- Matheus28 10y agoExactly. Per game room (each room is a process). I end up just using boxes that have 1 CPU core and run just that game room in there. Except for some dedicated servers that have 40+ cores, in which we run 40+ processes. On Agar.io doing all the collision checking and encoding the packets is the biggest bottleneck. Similarly for Diep.io. Number of players of course increases those two factors almost linearly. For example, Diep.io doesn't process shapes that aren't being transmitted to anyone.
- 10y ago
- gkop 10y agoHow much of a gap is remaining until stripped-down data channels libraries like librtcdcpp (C++) [0] and librtcdc (Python) [1] could be suitable for production? Is anyone here using one of these in production today? [0] https://github.com/chadnickbok/librtcdcpp https://github.com/chadnickbok/librtcdcpp [1] https://github.com/xhs/librtcdc https://github.com/xhs/librtcdc
- Matheus28 10y agoI haven't tried either of those, but they headed the right direction (other than the Boost and that log4cxx dependency, I'm very picky about what dependencies I bring into my projects).
- chadnickbok 10y agoHi! Nick here, author of librtcdcpp - mind elaborating on why you don't like log4cxx? Boost I get - I'm only using one or two easily-replaced headers, and would like to remove it next release :)
- Matheus28 10y agoHey! I'm just a bit opposed to having logging libraries in libraries that I'm using. I mean, if they're only needed for debug builds of the library I'm fine with that, but if I already have a logging library, bringing another into my project would be a bit unnecessary. Thanks for the reply!
- chadnickbok 10y agoHi! Thanks for linking my project - I'm currently trying to make librtcdcpp production-ready after having many issues with librtcdc. Patches very welcome!
- getkey 10y agoDo you adapt the amount of data sent based on the bandwidth? If so, how? To me the best way to do this involve knowing how often the TCP socket is doing retransmissions, which is an information typically not available at the WebSocket level.
- losvedir 10y agoHaha, whoa, I feel like I've spotted a celebrity! I mentor a kid here in rural Missouri and he and his friends play agar and diep. I don't know how they found them way out here, but they did and they love them (especially diep). Anyway, I've been idly thinking of ways to try to kindle an interest in programming in the guy, since he's very smart and seems to like computers. I played Cookie Clicker with him, and then showed him how to "hack" it from the console by playing with the JS a little bit (it's all local). But since he loves diep so much I think that would really give him motivation to learn more if he could fiddle with things in that game somehow. But I realize it's harder given that it's a client/server model. I don't suppose you have any ideas of things we could try? Is there a client-only mode where we can fiddle in the console? Or is the server code open source so I could run it locally or something? Oh, ha, and something that's been killing me... why's it called "diep"?
- Matheus28 10y agoHey, For Diep.io, it's completely server side and very little happens on the client side. That is intentional as Agar.io had a problem with "private servers" popping up which were actually people ripping (read stealing) the client side code, putting their ads in there, hosting it on their own website and pointing it at their server emulator. It comes from an old game I made when I was a kid called Diepix. There's no reason for the name "Diepix" other than sounding cool.
- deleted 10y ago[deleted]
- Insanity 10y agoI have not seen the game but to me it ushers upp images of going into a cave or a hole. Diep actually does mean _deep_ in my native language. Thanks for clarifying where the name comes from :-)
- javajosh 10y agoOther than hiding your code behind an API, were there any other ways to protect your IP?
- TerselyCogent 10y agoI think calling WebRTC a behemoth is a bit of an understatement. Excuse my sharp-tongued criticism, since I understand a lot of hard work has gone into it, but WebRTC has no regard for interoperability. As of now, it is nothing more to me than a VPN deanonymizing exploit. WebRTC leaks true IP addresses unless it is outright disabled in [supported] browsers. It is a huge annoyance, and I would be hard-pressed to view it as more than a gimmick that complicates the already messy landscape of web development.
- hellbanner 10y agoCool games! How do you do lag compensation in your games? (Prediction? Position interpolation?) OT question.. how much $ do you make on those?
- Jimmy24 10y agoWhy no Diep.io updates ?
- Jimmy24 10y agoWhy no Diep.io updates ?
- gafferongames 10y agoHi Matheus, please contact me. I am the author of libyojimbo (http://www.libyojimbo.com http://www.libyojimbo.com) and I have an idea that I think you'll find interesting.