WebGL build not working

Options
Hey all,

So there's little info currently on the state of photon + webgl (when used with unity), however dotted around the website it states that photon can be built along with webgl unity builds. However i'm having issues here. My setup is as follows:

- using photon server sdk 4.0.28.2962 (latest version)
- a custom application built on top of the photon server sdk (this seems to work fine with all testing)
- unity 5.4.1f1 (latest version)
- imported the unity3d dll from the photon server sdk into unity

When running the webgl build in the browser, I get the error "external function 'pthread_create' is missing..." which is ultimately stating that something in the code is trying to use a thread, which is not currently supported. I've managed to isolate the location of the issue, which is coming from PhotonPeer.Connect().

Is webgl currently not actually supported when using the photon server sdk? Or am I doing something wrong here?

As always, any help would be greatly appreciated.

Comments

  • chvetsov
    Options
    hi, there.
    this topic about server side development. please use correct section of forum to post your questions related to client side development. because it is easier for client side developer to see your questions
  • Tobias
    Options
    > imported the unity3d dll from the photon server sdk into unity

    This is part of the problem for WebGL. You will need to use the Client SDK for Unity from our page to get all assemblies for WebGL support. The Server SDK just has the dll for some test apps and reference. Not to replace a complete client SDK.

    WebGL will use WebSockets and for that, we have additional sources and libs.
  • @chvetsov my bad, will keep that in mind next time.

    @Tobias thanks again Tobias, I knew I must have been doing something wrong. I will give that a try :)
  • donnysobonny
    edited September 2016
    Options
    It looks like my issue was actually the fact that I was attempting to use the UDP protocol when constructing the PhotonPeer:

    private PhotonPeer peer = new PhotonPeer(new Listener(), ConnectionProtocol.Udp);

    I have changed it to use the WebSocket protocol, and imported the libraries that you have suggested and that appears to have fixed the threading error.


    I have come accross another error however. Connection fails, and IPhotonPeerListener.DebugReturn() reports the following:

    Debug Return: ERROR - Connect failed. SocketImplementationConfig is null for protocol WebSocket: {(ConnectionProtocol)Udp=(MonoType)ExitGames.Client.Photon.SocketUdp, (ConnectionProtocol)Tcp=(MonoType)ExitGames.Client.Photon.SocketTcp}

    As a result I don't manage to create a successful connection with the server...

    I've set up the web socket listeners in the photon server config, but i'm not quite sure what that error is suggesting? Would you have any ideas?

    Otherwise, let me know if you want some code examples of what i'm doing.
  • Tobias
    Options
    In the newer libs, you can (have to?!) setup the photon socket implementation per ConnectionProtocol.
    The websocket protocols should be set to use the SocketWebTcp class.

    In LoadBalancing for Unity, we do this:
    
                // to support WebGL export in Unity, we find and assign the SocketWebTcp class (if it's in the project).
                // alternatively class SocketWebTcp might be in the Photon3Unity3D.dll
                Type socketTcp = Type.GetType("ExitGames.Client.Photon.SocketWebTcp, Assembly-CSharp", false);
                if (socketTcp == null)
                {
                    socketTcp = Type.GetType("ExitGames.Client.Photon.SocketWebTcp, Assembly-CSharp-firstpass", false);
                }
                if (socketTcp != null)
                {
                    this.SocketImplementationConfig[ConnectionProtocol.WebSocket] = socketTcp;
                    this.SocketImplementationConfig[ConnectionProtocol.WebSocketSecure] = socketTcp;
                }
    
    I am not sure which setup/package you use now, so please try to use this as guide. The SocketWebTcp class should be in your package. You don't have to use GetType, by the way. This is only done because we have to be very modular about the classes we use on some Unity export platforms.
  • donnysobonny
    edited September 2016
    Options
    I'm not using a pre-built package if that is what you're asking? The server-end is a custom application which doens't resemble the pre-built applications that come with the photon server sdk, so the client-side stuff is pretty much custom too.

    The above code that you've provided, what scope does that exist within? That "SocketImplementationConfig" property for example, I'm not sure where I can access that (what class it exists withing)?

    EDIT

    Derp... you're obviously talking about PhotonPeer.SocketImplementationConfig :)

    Will give that a try. Thanks again!
  • donnysobonny
    edited September 2016
    Options
    Okay great so with a little bit more fiddling, I have been able to get as far as to see the connection being attempted on the server-side. However, I seem to be having an issue with the port on the server.

    In my config, I have the websocketlistener set up like so:

    <WebSocketListeners> <WebSocketListener IPAddress="0.0.0.0" Port="9090" DisableNagle="true" InactivityTimeout="10000"> </WebSocketListener> </WebSocketListeners>
    There's a few entries in the startup log which appear to show the listener being set up without any issues:
    3548: 12:56:36.591 - Adding WebSocket TCP listener on: 0.0.0.0: 9090 with a listen backlog of: 150
    3548: 12:56:36.591 - Nagle disabled
    My code would probably not make a huge amount of sense if just copied and pasted in here (since it's pretty much a wrapper around the usual client code that you build with photon, to make my life easier), but from unity i'm calling the equivalent of:
            PhotonPeer peer = new PhotonPeer(new Listener(), ConnectionProtocol.WebSocket);
            peer.ChannelCount = (byte)4;
            peer.Connect("ws://127.0.0.1:9090", "FIO.MasterServer");
    The server seems to see the request come in, but it claims that the port 9090 is "unknown":
    2016-09-21 12:53:34,046 [14] DEBUG Photon.SocketServer.ApplicationBase - OnInit - ConnID=3, IP 127.0.0.1 on port 9090, type = WebSocketListener
    2016-09-21 12:53:34,049 [11] ERROR Photon.SocketServer.Peers.ManagedPeer - System.Exception: Peer tried connected in unknown port: 9090
       at FIO.MasterServer.Application.CreatePeer(InitRequest initRequest) in C:\Users\Joe\Documents\Visual Studio 2015\Projects\FIO\FIO.MasterServer\Application.cs:line 114
       at Photon.SocketServer.Peers.ManagedPeer.CreatePeerBase(InitRequest initRequest) in h:\svncontent\photon-socketserver-sdk_cloud\src\Photon.SocketServer\Peers\ManagedPeer.cs:line 189
    I've tried a few different things and port 9090 definitely seems like it is accessible and not being blocked by the firewall... any ideas what might be causing this?

    EDIT

    Today has totally just been one of those days! After spending hours on the above, it was down to me not adding a section in the ApplicationBase.CreatePeer method for a peer connecting via a websocket >.<

    Time to take a holiday I think!!

    That's everything working now though. Thanks again for the help.
  • Tobias
    Options
    Thanks for the edit and update! Very good to read you found it. This was sneaky :)