setup photon server for webGL
The whole answer can be found below.
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).
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
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.
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.
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>
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.
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
Hi @Flatron, could you please check your Photon server certificate? If it is valid, signed and trusted by your browser?
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
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.
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
And what about browser, when you try to open
https://photon-dev.emergents.com:19093
? You should get something like this:
I have this:
](https://ibb.co/VDfTpwc)
@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.
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.
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:
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:
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:
ExitGames.Client.Photon.MyAction:Invoke()
ExitGames.Client.Photon.TPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
Photon.Pun.PhotonHandler:Dispatch()
Photon.Pun.PhotonHandler:FixedUpdate()
@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
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.
@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