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

Socket.RemoteEndPoint exception in OnWsDisconnected #116

Closed
Dmitriy147 opened this issue Feb 19, 2021 · 7 comments
Closed

Socket.RemoteEndPoint exception in OnWsDisconnected #116

Dmitriy147 opened this issue Feb 19, 2021 · 7 comments

Comments

@Dmitriy147
Copy link

In my websocket chat server I try to use Socket.RemoteEndPoint to show the IP-adress of client, but ,unfortunately, in case "OnWsDisconnected" in attemp to show IP of disconnected client it is an exception like:
System.ObjectDisposedException: "Cannot access a disposed object.
ObjectDisposed_ObjectName_Name".

With showing client ID in this situation has no problems!
Is it any way to show IP of disconnected client without making array of all clients IP?

@chronoxor
Copy link
Owner

Fixed in 5.0.8 please try!

@Dmitriy147
Copy link
Author

Dmitriy147 commented Feb 19, 2021

No effect on 5.0.8.. From Google Chrome connect by websocket throw chat/index.html - connect by websockets - than disconnect - exception appeared..
My code:
public override void OnWsDisconnected()
{
Logger.Log("Отключился: " + Socket.RemoteEndPoint, 0, true);
Logger.Log("ID: " + Id.ToString(), 1, ful_log);
}

@chronoxor
Copy link
Owner

It's the behavior of .net Socket it will dispose RemoteEndPoint property on Socket.Close() call. OnWsDisconnected() is called after the socket is closed.

What do you think of introducing OnWsDisconnecting() callback with valid connected socket in it?

@chronoxor
Copy link
Owner

The flow can be the following:

OnWsDisconnecting();
Socket.Close();
OnWsDisconnected();
Socket.Dispose();

@Dmitriy147
Copy link
Author

would be nice!

@chronoxor
Copy link
Owner

In our logs we store this information in a following way:

2021-02-18T00:55:53.926Z [0x000023B4] INFO  endpoints - TCP config session with Id '0ccb739f-7184-11eb-b134-240a646eaeae' connected to remote address '127.0.0.1' and port 58148
....
2021-02-18T00:55:56.029Z [0x000023B4] INFO  endpoints - TCP config session with Id '0ccb739f-7184-11eb-b134-240a646eaeae' disconnected

@chronoxor
Copy link
Owner

New handlers implemented.

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