PeerJS networking test

Show us your completed creations made in Construct 2

Post » Sun Oct 27, 2013 11:50 pm

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.R0J0hound2013-10-28 00:18:55
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Oct 28, 2013 12:15 am

@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.

[QUOTE=R0J0hound] 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[/QUOTE] retrodude2013-10-28 00:15:42
B
18
S
4
G
3
Posts: 436
Reputation: 4,801

Post » Mon Oct 28, 2013 12:36 am

@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.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Oct 28, 2013 2:58 am

@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.   

retrodude2013-10-28 03:01:00
B
18
S
4
G
3
Posts: 436
Reputation: 4,801


Return to Completed Creations

Who is online

Users browsing this forum: No registered users and 11 guests