Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NetworkTransport.Connect and WebGL, how does it work?

Discussion in 'Multiplayer' started by ian_facepunch, Sep 26, 2016.

  1. ian_facepunch

    ian_facepunch

    Joined:
    Mar 16, 2015
    Posts:
    22
    So using LLAPI, to make a connection using NetworkTransport we call the following functions:

    On Server:

    int hostId = NetworkTransport.AddHost(topology,8888);

    On Client:

    int hostId = NetworkTransport.AddHost(topology); //no port number
    myConnectionId = NetworkTransport.Connect(hostId, "127.0.0.1", 8888, 0, out error);

    but how do we make a connection using Websockets for WebGL?

    I know that NetworkTransport.AddWebsocketHost is only called on the server so in that case what hostID do I pass into NetworkTransport.Connect for the WebGL client?

    The samples / docs are really unclear.

    Ian
     
  2. ian_facepunch

    ian_facepunch

    Joined:
    Mar 16, 2015
    Posts:
    22
    Figured this out...

    Just used:

    int hostId = NetworkTransport.AddHost(topology,0)

    Had to look into the NetworkClient source to figure this out though. Also, I'm guessing WebSockets only works as a connection method when building for WebGL?
     
  3. fhamel_bhvr

    fhamel_bhvr

    Joined:
    Mar 24, 2015
    Posts:
    6
    Thank you @ian_facepunch! Years later this answer proved useful to us as well ;-)