Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onError not called for error return from the server #56

Closed
royibernthal opened this issue Apr 20, 2023 · 3 comments
Closed

onError not called for error return from the server #56

royibernthal opened this issue Apr 20, 2023 · 3 comments

Comments

@royibernthal
Copy link

When emitting the "message" event, I'm throwing an exception on the server on purpose.
I'm expecting OnError to trigger, but it doesn't.

This is the exception packet I captured from the server, which doesn't trigger OnError on the client.

42["exception",{"status":"error","message":"test"}]

using UnityEngine;
using System;

public class Test : MonoBehaviour
{
    void Start() {
        var uri = new Uri("ws://localhost:8090");
        
        var socket = new SocketIOUnity(uri);

        socket.OnConnected += (sender, e) =>
        {
            Debug.Log("OnConnected");

            socket.Emit("message", "bla"); // throwing an exception on the server on purpose
        };

        socket.OnError += (sender, e) => {
            Debug.Log("OnError: " + e); // should be triggered with exception from the server, but never triggered
        };

        socket.Connect();
    }
}
@itisnajim
Copy link
Owner

replace ws: by http: and set the transporter to WebSocket like in:

var uri = new Uri("http://localhost:8090");
socket = new SocketIOUnity(uri, new SocketIOOptions
{
    Query = new Dictionary<string, string>
        {
            //{"token", "UNITY" }
        }
    ,
    Transport = SocketIOClient.Transport.TransportProtocol.WebSocket
});

add the other callbacks so you know in which phase the socket get disconnected:

        socket.OnError += (sender, e) => {
            Debug.Log("OnError: " + e);
        };

        socket.OnPing += (sender, e) =>
        {
            Debug.Print("Ping");
        };
        socket.OnPong += (sender, e) =>
        {
            Debug.Print("Pong: " + e.TotalMilliseconds);
        };
        socket.OnDisconnected += (sender, e) =>
        {
            Debug.Print("disconnect: " + e);
        };
        socket.OnReconnectAttempt += (sender, e) =>
        {
            Debug.Print($"{DateTime.Now} Reconnecting: attempt = {e}");
        };

@royibernthal
Copy link
Author

I did everything you said, none of the callbacks were called except for the usual ping pong.

@royibernthal
Copy link
Author

It seems socket.On("exception"...) works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants