setup photon server for webGL

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Photon Server.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

setup photon server for webGL

Flatron
2021-08-17 08:42:25

I have a problem connecting to the photon server by unity webGL
if it's possible please help me to config my photon server(Photon Server v5)
normally I can connect to my photon server but when I want to build a WebGL and I change the platform to WebGL, the connection to the server always fails.

Comments

JohnTube
2021-08-17 22:42:13

Hi @Flatron,

Thank you for choosing Photon !

I think it's most likely a known issue in PhotonServer.config:
Please replace "/*" with "/+" in HttpListeners and try again.

Flatron
2021-08-18 09:31:44

I did this and now I can connect in unity but in the browser, I cannot connect.
these are the errors from the browser console:

WebSocket connection to ‘wss://photon-dev.emergents.com:19093/?libversion=4.1.6.4&sid=30&app=NameServer’ failed:
_SocketCreate @ EmergentsDemo.framework.js:2
EmergentsDemo.loader.js:1 writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!
printErr @ EmergentsDemo.loader.js:1
EmergentsDemo.framework.js:2 Exiting receive thread. Server: wss://photon-dev.emergents.com:19093:0 Error: Abnormal disconnection.
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String)
ExitGames.Client.Photon.d__12:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

here is our config:

<HTTPListener  
        Name="*:[PORT]::Master"  
        IPAddress="0.0.0.0"  
        Port="19090"  
        DisableNagle="true"  
        InactivityTimeout="10000"  
        Secure="true">  
        <Routing>  
          <Route  
            Url="/+"  
            OverrideApplication="Master"  
            PeerType="WebSocket"  
            Counters="false"  
          />  
        </Routing>  
      </HTTPListener>  
      <HTTPListener  
        Name="*:[PORT]::Game"  
        IPAddress="0.0.0.0"  
        Port="19091"  
        DisableNagle="true"  
        InactivityTimeout="10000"  
        AppDataInactivityTimeout="15000"  
        Secure="true">  
        <Routing>  
          <Route  
            Url="/+"  
            OverrideApplication="Game"  
            PingEvery="2000"  
            PeerType="WebSocket"  
            Counters="false"  
          />  
        </Routing>  
      </HTTPListener>  
      <HTTPListener  
        Name="*:[PORT]::NameServer"  
        IPAddress="0.0.0.0"  
        Port="19093"  
        DisableNagle="true"  
        InactivityTimeout="10000"  
        AppDataInactivityTimeout="15000"  
        PermittedOrigins="our server url"  
		Secure="true">  
        <Routing>  
          <Route  
            Url="/+"  
            OverrideApplication="NameServer"  
            PeerType="WebSocket"  
            Counters="false"  
          />  
        </Routing>  
      </HTTPListener>

chuckyw
2021-08-19 08:39:21

Hi @Flatron, what client library are you using to connect to the server? PUN or Realtime Photon? Which version? Could you please also post your server log (Photon-Default-xxxx.log or Photon-Loadbalancing-xxx.log)? Thank you.

Flatron
2021-08-19 10:16:43

I am using PUN2
version pun:2.34.1 photon lib:4.1.6.4

Photon-LoadBalancing-20210819.log at:
https://drive.google.com/file/d/1HrJPq8TOHQAe1GuxoLg_C7TI-FYRuGlx/view?usp=sharing

Thank you

chuckyw
2021-08-20 18:39:47

Hi @Flatron, could you please check your Photon server certificate? If it is valid, signed and trusted by your browser?

Flatron
2021-08-23 14:19:43

Any documentation on how to create a valid, signed, and trusted by browser?
We already created a server certificate based on https://doc.photonengine.com/zh-CN/server/current/operations/certificate-setup

chuckyw
2021-08-23 21:10:28

The approach is correct, but due to browser changes, it is almost impossible to find out what is going on, as browsers (checked on Firefox and Chrome) do not report exact connection error into console anymore. But it is the most likely that your browser doesn't trust the cert. To enable it, please try to open https://photon-dev.emergents.com:19093 in your browser (replace wss with https, see section https://doc.photonengine.com/zh-CN/server/current/operations/certificate-setup#chrome_console_error__err__cert__invalid__authority), then allow it to connect even if untrusted, but then you'd have to save the cert to a file (check here https://www.ge.com/digital/documentation/historian/version91/t_hgs_enabling_trust_for_a_self_signed_certificate.html) and then install the cert as a Trusted root cert. Then the connection should work.

You can also try to use curl to debug any other errors with cert on wss. Try to use a command similar to this:

curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: photon-dev.emergents.com" -H "Origin: https://photon-dev.emergents.com" "https://photon-dev.emergents.com:19093/?clientversion=4.1.5.2&sid=30&app=NameServer"  

The other way is getting a cert from a trusted authority.

Flatron
2021-08-24 12:19:35

Thanks a lot for your help.
this is curl responce:

curl -i -N -H “Connection: Upgrade” -H “Upgrade: websocket” -H “Host: photon-dev.emergents.com” -H “Origin: https://photon-dev.emergents.com” “https://photon-dev.emergents.com:19093/?clientversion=4.1.5.2&sid=30&app=NameServer”  
HTTP/1.1 400 Handshake headers do not include an “Sec-WebSocket-Version” header  
Content-Type: text/html  
Connection: Keep-Alive  
Keep-Alive: timeout=10  
Cache-Control: private, max-age=0, no-cache, no-store  
Pragma: no-cache  
Expires: Mon, 29 Apr 2013 21:44:55 GMT  
Access-Control-Allow-Origin: https://photon-dev.emergents.com  
Content-Length: 66 (edited)

We got the certificate from trusted authority

chuckyw
2021-08-24 12:30:53

And what about browser, when you try to open https://photon-dev.emergents.com:19093 ? You should get something like this:

Flatron
2021-08-25 04:50:20

I have this:

[

](https://ibb.co/VDfTpwc)

chuckyw
2021-08-25 12:15:07

@Flatron oh.. and you still can't connect? Well, I am a little bit out of ideas, to be honest:-) I've tried the same setup and when the certificate is considered valid by Chrome, it all works for me...

Could you please rebuild the app with PUN logging set to Full and Network logging set to ALL (both in PhotonServerSettings.asset) and post log from browser console while trying to connect to the server?

TaherSamadi
2021-08-25 13:24:37

Connecting...
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PhotonClassHandler:Connect()
Assets.Scripts.Core.Game.PhotonRulesEngineHandler:Setup()
Core.Game.RulesEngineConnector:Setup(Boolean)
Core.Game.GameplayController:Setup()
Core.Game.GameplayController:Start()

emergentstest.framework.js:2 Using NameServerPortInAppSettings: 19093
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String)
Photon.Realtime.LoadBalancingClient:GetNameServerAddress()
Photon.Realtime.LoadBalancingClient:get_NameServerAddress()
Photon.Realtime.LoadBalancingClient:ConnectToNameServer()
Photon.Pun.PhotonNetwork:ConnectToBestCloudServer()
Photon.Pun.PhotonNetwork:ConnectUsingSettings(AppSettings, Boolean)
Photon.Pun.PhotonNetwork:ConnectUsingSettings()
PhotonClassHandler:Connect()
Assets.Scripts.Core.Game.PhotonRulesEngineHandler:Setup()
Core.Game.RulesEngineConnector:Setup(Boolean)
Core.Game.GameplayController:Setup()
Core.Game.GameplayController:Start()

emergentstest.framework.js:2 new SocketWebTcp() for Unity. Server: wss://photon-dev.emergents.com:19093
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String)
ExitGames.Client.Photon.SocketWebTcp:.ctor(PeerBase)
System.Reflection.MonoCMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoCMethod:InternalInvoke(Object, Object[])
System.Reflection.MonoCMethod:DoInvoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MonoCMethod:Invoke(BindingFlags, Binder, Object[], CultureInfo)
System.RuntimeType:CreateInstanceImpl(BindingFlags, Binder, Object[], CultureInfo, Object[], StackCrawlMark&)
System.Activator:CreateInstance(Type, BindingFlags, Binder, Object[], CultureInfo, Object[])
System.Activator:CreateInstance(Type, Object[])
ExitGames.Client.Photon.PhotonPeer:Connect(String, String, String, Object, Object)
Photon.Realtime.LoadBalancingClient:ConnectToNameServer()
Photon.Pun.PhotonNetwork:ConnectToBestCloudServer()
Photon.Pun.PhotonNetwork:ConnectUsingSettings(AppSettings, Boolean)
Photon.Pun.PhotonNetwork:ConnectUsingSettings()
PhotonClassHandler:Connect()
Assets.Scripts.Core.Game.PhotonRulesEngineHandler:Setup()
Core.Game.RulesEngineConnector:Setup(Boolean)
Core.Game.GameplayController:Setup()
Core.Game.GameplayController:Start()

emergentstest.framework.js:2 WebSocket connection to 'wss://photon-dev.emergents.com:19093/?libversion=4.1.6.4&sid=30&app=NameServer' failed:
_SocketCreate @ emergentstest.framework.js:2
emergentstest.loader.js:1 writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!
printErr @ emergentstest.loader.js:1
emergentstest.framework.js:2 Exiting receive thread. Server: wss://photon-dev.emergents.com:19093:0 Error: Abnormal disconnection.
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String)
ExitGames.Client.Photon.d__12:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

_JS_Log_Dump @ emergentstest.framework.js:2
emergentstest.framework.js:2 SocketWebTcp.Disconnect()
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String)
ExitGames.Client.Photon.SocketWebTcp:Disconnect()
ExitGames.Client.Photon.d__12:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

emergentstest.framework.js:2 TPeer.Disconnect()
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String)
ExitGames.Client.Photon.TPeer:Disconnect()
ExitGames.Client.Photon.IPhotonSocket:b__52_0()
ExitGames.Client.Photon.MyAction:Invoke()
ExitGames.Client.Photon.TPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
Photon.Pun.PhotonHandler:Dispatch()
Photon.Pun.PhotonHandler:FixedUpdate()

emergentstest.framework.js:2 SocketWebTcp.Disconnect()
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String)
ExitGames.Client.Photon.SocketWebTcp:Disconnect()
ExitGames.Client.Photon.TPeer:StopConnection()
ExitGames.Client.Photon.TPeer:Disconnect()
ExitGames.Client.Photon.IPhotonSocket:b__52_0()
ExitGames.Client.Photon.MyAction:Invoke()
ExitGames.Client.Photon.TPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
Photon.Pun.PhotonHandler:Dispatch()
Photon.Pun.PhotonHandler:FixedUpdate()

emergentstest.framework.js:2 OnDisconnected
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Assets.Scripts.Core.Game.PhotonRulesEngineHandler:OnDisconnected()
UnityEngine.Events.UnityAction:Invoke()
UnityEngine.Events.InvokableCall:Invoke()
UnityEngine.Events.UnityEvent:Invoke()
PhotonClassHandler:OnDisconnected(DisconnectCause)
Photon.Realtime.ConnectionCallbacksContainer:OnDisconnected(DisconnectCause)
Photon.Realtime.LoadBalancingClient:OnStatusChanged(StatusCode)
ExitGames.Client.Photon.<>c__DisplayClass109_0:b__0()
ExitGames.Client.Photon.MyAction:Invoke()
ExitGames.Client.Photon.TPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
Photon.Pun.PhotonHandler:Dispatch()
Photon.Pun.PhotonHandler:FixedUpdate()

chuckyw
2021-08-25 15:52:36

@Flatron one more question - what Unity version do you use to build the client? Unity 2018+ is needed to support TLS1.2, but I suppose, you are using newer.. Also what OS?

TaherSamadi
2021-08-25 21:11:34

Unity 2020.3.16f1
OS: macOS Big Sur V 11.2.3

TaherSamadi
2021-08-25 22:21:26

tried on windows 10. also tried in a complete new project with photon demo samples, no luck.
we are able to connect to photon cloud but not to our self hosted photon server.
our photon server sdk version: photon-server-sdk_v5-0-12-24499-rc1

chvetsov
2021-08-26 07:32:49

hi, @TaherSamadi

could you try this on another machine?
for instance on some VM or friends pc

best,
ilya

TaherSamadi
2021-08-26 09:29:19

Hi, we did test on 2 different PCs. Still not able to connect

TaherSamadi
2021-08-27 17:25:12

Update: we were able to connect using 443 port.

chuckyw
2021-08-31 11:09:52

@TaherSamadi did you use this port on both, server and client? Well, I'd suggest to check for some firewall issues, it does not seem like a photon server configuration issue.. Btw, did you also tried running the server on a different machine, or just clients?

Back to top