doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

About SocketIo Server Middleware Permissions #231

Closed chohoo89 closed 2 years ago

chohoo89 commented 2 years ago

Hi.

Authorization is verified with middleware in My socketio server. If the client does not give me a proper token, the middleware calls the connection close.

io.of('/Alert').use((socket, next) => {
  // Vertified Token Header
  if (!Vertified) {
    socket.disconnect(); // event occurs
    next(new Error('Auth Error'));
    return;
  }
  next();
}).on('connection', async socket => {

}

However, the ondisconnected event cannot be called in the C# client.

// This event never called
socket.OnDisconnected += async (sender, e) => {
    if (e == "io server disconnect") {
         return;
    }
     await Sokect_Connection(socket_token);
};

Middleware disconnect event from server doesn't support calling from C# client? thank you. 😅

doghappy commented 2 years ago

Can you try this?

socket.OnError += Socket_OnError;

...

private void Socket_OnError(object sender, string e)
{
    Console.WriteLine(e);
}

outpu:

Auth Error

The output is from: next(new Error('Auth Error'));

chohoo89 commented 2 years ago

Can you try this?

socket.OnError += Socket_OnError;

...

private void Socket_OnError(object sender, string e)
{
    Console.WriteLine(e);
}

outpu:

Auth Error

The output is from: next(new Error('Auth Error'));

Thanks for replying. 😊 Is the socket.OnError function an event that only reacts to the server's new Error() function?