How do I restart the multiplayer connection properly?

0 favourites
  • 4 posts
From the Asset Store
Plumber wanna be? Connect pipes in rotary manner. Simply tap on them!
  • Hello,

    I have a game (following the multiplayer tutorials). When I try to reset the connection after the game (so the players can start over) I get all sorts of errors:

    - Sometimes leaving + disconnecting causes the Peer object to be destroyed, and the console shows red errors about RTC errors. Like these:

    On the host:

    Peer '0OF8' datachannel 'o' error: RTCErrorEvent dc.onerror peer.js:4 domSide.js:49 [Multiplayer] Peer 'playerHost' (0OF8) error: RTCErrorEvent _OnPeerError domSide.js:49 peer.js:4 Peer '0OF8' datachannel 'r' error: RTCErrorEvent dc.onerror peer.js:4 domSide.js:49 [Multiplayer] Peer 'playerHost' (0OF8) error: RTCErrorEvent _OnPeerError domSide.js:49 peer.js:4 Peer '0OF8' datachannel 'u' error: RTCErrorEvent dc.onerror peer.js:4 domSide.js:49 [Multiplayer] Peer 'playerHost' (0OF8) error: RTCErrorEvent _OnPeerError domSide.js:49

    On the peer:

    Peer 'AYKF' datachannel 'o' error: RTCErrorEvent dc.onerror editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/peer.js:4 editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/domSide.js:49 [Multiplayer] Peer 'playerPeer' (AYKF) error: RTCErrorEvent _OnPeerError editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/domSide.js:49 editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/peer.js:4 Peer 'AYKF' datachannel 'u' error: RTCErrorEvent dc.onerror editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/peer.js:4 editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/domSide.js:49 [Multiplayer] Peer 'playerPeer' (AYKF) error: RTCErrorEvent _OnPeerError editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/domSide.js:49

    - If the host left the room, the other players get the following:

    "Cannot parse off host time from pong response _OnPong editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/peer.js:20 _DoOnMessage editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/peer.js:22 _OnMessage editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/peer.js:21 dc.onmessage editor.construct.net/r234-4/plugins/web/multiplayer/c3runtime/peer.js:4"

    - I tried to print the connection parameters on start of the layout:

    --- The first time I run the game, the room name, signaling server name,... are all empty strings.

    --- After I connect, play, disconnect and leave, and then restart the layout, the names are still saved in the multiplayer object. Shouldn't leaving erase this data?

    - On peers, I destroy the Peer objects at the start of layout (since the host will create them).

    In short, what is the proper way to close the connection (including the destruction of Peer objects) so that when I restart the layout and the code runs from the start, it works just fine like the initial time?

    I have tried many combinations of leaves/disconnects/destroys..etc, with no avail. Any guidance is appreciated :)

    Thanks a lot.

    Tagged:

  • drive.google.com/file/d/1FmEtzZJt_18EVaAoL5sBFS6h69xCr1OD/view

    i made this a short while ago if you want. IT makes it so that you control pretty much everything instead of letting the plugin do it for you, game state and stuff

    --- After I connect, play, disconnect and leave, and then restart the layout, the names are still saved in the multiplayer object. Shouldn't leaving erase this data?

    not really, i mean you don'T really explain anything but, the host probably detects this as a temporary disconnection and tries to restore the game

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for your reply.

    For anyone that would face similar issue, I guess I found a solution, which involves:

    - Solving some bugs on my side. Like re-activating/deactivating initial groups after restarting. Also some steps were working fine, but causing problems under the hood (!!!). I revisited the pong tutorial to fix them.

    - This is the leave code (called On Start of Layout) that worked for me (so far!):

    Basically:

    - If host: Leave room, then when left room, leave server.

    Skipping the "then" step and disconnecting directly from the server (using either of the Disconnect options in the Multiplayer object) will cause the the preview (in Debug mode) to crash, along with the editor !!!

    - If peer: Disconnect from signaling server directly.

    Now I can restart smoothly.

    Before using the above code, I had to click connect, then wait for the connection to be refused by the server, then click connect again, and now I can restart properly. (connect=the signalling sequence of the pong tutorial).

    Also, the Leave action has this in the description: "Peer connections are not affected". What does it mean, exactly?

    - Does it mean "It only works for the host, and peers have to Disconnect instead".

    (Which aligns with my findings; because in earlier tries, I used Leave without the "If host" check, and it didn't work for peers (I had to re-connect twice).

    - Or, "Peers will not be kicked from the room even if the host leaves"?

    Ashley

    Thanks.

  • Update:

    I revised my whole code, and simplified it. Instead of all the "leave management" I was trying to make, I added a simple line to my initial multiplayer function (the one that starts the signaling process):

    - If the user is connected to the signaling server: disconnect, wait 2 secs, connect.

    Else: connect.

    A lot of issues disappeared at once after this line! but I am still facing some irregular issues now.

    For example; the first peer to join a room (after the host) will usually be kicked right after joining. The 2nd, 3rd.. players join just fine. I traced that to a syncing issue, where one of the synced objects is not created for that 1st player, and for some reason is created for the others. Sometimes, this doesn't happen at all.. I have spent hours tracing the causes of this issue, and disabled most of my multiplayer code in a try to find the root of this problem.

    I tried this with the Pong sample as well. I only added a button in the game screen that only does the following:

    - Leave room (I tested other situations where I disconnect from server instead).

    - Go to Login layout.

    Trying to make the peer leave and rejoin would cause some bugs (duplicate objects, sometimes it did not log in...)

    What is interesting is that this only happens in preview (I am testing 4 previews at once). After I uploaded my game to itch.io and tested with 2 windows, this did not happen -so far-.

    I will keep improving my code and will see how thing go!

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