Answer the question
In order to leave comments, you need to log in
Websocket Why doesn't the OnClose method work?
Hello, I am writing a ws client in c#
For the client, I used this: https://github.com/sta/websocket-sharp
I did everything according to the documentation, everything works well, but for some reason, if you take and specifically turn off the server, then nothing on the client not happening.
Here's how I did it:
public static WebSocket ws;
private void wsConnector()
{
addLog("Подключаемся");
using (ws = new WebSocket("ws://127.0.0.1:3322"))
{
ws.OnMessage += (sender, e) => onMessage(e.Data);
ws.OnOpen += (sender, e) => onOpen();
ws.OnError += (sender, e) => onError();
ws.OnClose += (sender, e) => {
addLog("Отключаемся от сервера");
};
}
ws.Connect();
}
public Form1()
{
InitializeComponent();
wsConnector();
}
Answer the question
In order to leave comments, you need to log in
It did not work with websocket-sharp, but judging by your code, by the time ws.Connect your socket should already be invalid, because. when exiting the using block, Dispose is called...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question