0 Favourites

PeerJS networking test

  • So I decided to take the plunge and tinker around with some networking in C2. I found a javascript library PeerJS which uses webrtc on browsers that support it (aka Chrome and FireFox). It seemed appealing to me, as once I got a wrapper working I wouldn't need to write any server side code to get multiple devices connected together.

    So here's a relatively simple tech test of it in action. The first person becomes the host and all others connect to him. Each player has a box to drag around and all the other players box's positions are updated at an arbitrary 20fps. Supposedly I can have up to 50 players connected at once.

    So without further ado, join the box dragging nonsense:

    http://tinyurl.com/kherptw

    [EDIT]

    Nonsense indeed, after further testing I noticed quite a few things I did wrong with handling the networking events. On top of that my internet and pc are pretty slow right now.

  • R0J0hound

    Wow this sounds like a really cool idea (If I'm understanding this correctly). Will it work for multi-platform games? For example; I begin hosting and then someone else uses the browser on their smartphone to connect to me?

    Also you mentioned up to 50 players connecting at once. But is that with limited sprite objects on the canvas with only one or two objects? I'd imagine updating multiple objects at once would showcase some kind of frame-rate issue.

    So I decided to take the plunge and tinker around with some networking in C2. I found a javascript library PeerJS which uses webrtc on browsers that support it (aka Chrome and FireFox). It seemed appealing to me, as once I got a wrapper working I wouldn't need to write any server side code to get multiple devices connected together.

    So here's a relatively simple tech test of it in action. The first person becomes the host and all others connect to him. Each player has a box to drag around and all the other players box's positions are updated at an arbitrary 20fps. Supposedly I can have up to 50 players connected at once.

    So without further ado, join the box dragging nonsense:

    http://tinyurl.com/kherptw

  • retrodude

    I've got it working with chrome and firefox on my pc and on my android tablet. Webrts, which peerjs is based on is still in an experimental state and I think mainly google and mozilla are still working on getting a standardized spec for it. But yeah, eventually it should be useable everywhere. 50 connections at once is the limit for the peerjs server. Which is fine, as if you really needed more you could make your own server based on peerjs' server's source. A game will probably slow long before 50 players though. The main draw of peerjs is it's supposed to be fast since all the server does is act as a broker to connect two devices and then the devices can communicate directly without a server. My example is unfortunately very wip and i'm sure there are superior ways to setup the events I used.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • R0J0hound

    Regardless,

    Even if there were superior ways, you still managed to provide us with a great example. And I doubt you would need to host a game that supports 50 connections, maybe 4-10 maximum unless your making an mmorpg but that's a whole different side of things. This is actually amazing! Even if peerjs is experimental, a server that can hold 50 connections is probably above what most C2 users need!

    Hopefully there's more support for this feature. Thanks for taking the time and sharing Rojo.   <img src="smileys/smiley2.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)