Help~ Got connection failed: Error during WebSocket handshake: Unexpected response code: 400

Hello~

I have a problem connecting to the photon server by unity webGL. It's work fine in Unity Editor, but failed to make a WebSocket connection when being exported to H5 program. I've really have no idea with the problem. Help!


Here's some details:

Unity version:Unity 2019.4.36f1

Pun:2.40 Photon lib:4.1.6.11

Photon server:v5-0-12-24499-rc1


Logs:

I: new SocketWebTcp() for Unity. Server: wss://xxxxx.snowtime.fun:443

E: WebSocket connection to 'wss://xxxxx.snowtime.fun/?libversion=4.1.6.11&sid=30&app=' failed: Error during WebSocket handshake: Unexpected response code: 400

E: writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!

E: Exiting receive thread. Server: wss://xxxxx.snowtime.fun:443:0 Error: abnormal closure

I: SocketWebTcp.Disconnect()

I: TPeer.Disconnect()

I: SocketWebTcp.Disconnect()

Answers

  • Meep
    Meep ✭✭✭

    Port 443 doesn't look correct, it should be 19093 if you haven't modified the configuration file yourself.

    Make sure you have proper SSL certificates installed as well, and finally make sure you are on Secure WebSockets.

  • hi, @TPLuFFy

    could you share your config?

    @Tobias do you have any recommendation here

    best,

    ilya

  • Hi, @chvetsov

    Thx for the reply. I just uncomment the default config for test.


  • @Meep Thanks, I have uncomment the HTTPListener on 443, and also I've set the pem file under ./bin_Win64/certs. The connection works fine on the Unity Editor, 😥

  • Tobias
    Tobias admin
    edited July 2022

    It's work fine in Unity Editor, but failed to make a WebSocket connection when being exported to H5 program.

    What is a H5? Is it WebGL? Which browser (and version) do you use?

    Are you running client, webserver and Photon Server on the same host name? Do you even have a host name for the webserver?

  • @Tobias Yep, WebGL. Here is the screenshot with the info.


  • @TPLuFFy lets try to use native logging to see what is going on


    in PhotonServer.config right after instance node please add next xml code:

        <Log File="[CONFIG]/PhotonServer.Log.config"/>
    

    place file PhotonServer.log.config next to PhotonServer.config. Content should be like this:

    <?xml version="1.0" encoding="utf-8"?>
    <Configuration>
      <Instance Name="LoadBalancing">
        <Log Dump="true">
          <All Level="ERROR"/>
          <Photon Level="ERROR"/>
          <Config Level="INFO|WARN|ERROR"/>
          <WebSocket Level="TRACE|INFO|WARN|ERROR"/>
        </Log>
      </Instance>
    </Configuration>
    


    before testing please remove old logs and send us logs from bin_win64/log folder right after testing


    best,

    ilya

  • TPLuFFy
    TPLuFFy
    edited July 2022

    @chvetsov Here's all log files with follow steps. (Already remove old log files)

    1. Start as application (PhotonControl)
    2. Call "PhotonNetwork.ConnectUsingSettings();"
    3. Stop application (PhotonControl)


  • hi, @TPLuFFy

    I do not see that you set up logging correctly but there is some questions anyway

    How did you get your certificate? if it is self generated than it will not work with browser


    best,

    ilya

  • one more thing. did you see this page?

    Certificate Setup | Photon Engine


    best,

    ilya