R
R
Roman Rakzin2016-10-17 22:31:27
C++ / C#
Roman Rakzin, 2016-10-17 22:31:27

WebSocketSharp error when the server is disconnected or missing. How to handle the exception?

How to handle an exception if the connection is down or the server doesn't disconnect?

var ws = new WebSocket("ws://localhost/client_websocket")
            { 
                ws.OnOpen += (sender, e) => this.Connected();
            
                ws.OnMessage += (sender, e) => Console.WriteLine(e.Data);
    
    
                ws.OnError += (sender, e) =>//делаем что-то при ошибке
    
                ws.OnClose += (sender, e) => //делаем что-то при отключении
    
                ws.Connect();
                while (true)
                {
                }
            }

[1]: bCPUR.pnghttps://i.stack.imgur.com/bCPUR.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Rakzin, 2016-10-18
@TwoRS

It was just necessary to turn off log
ws.Log.Output = (LogData data, string path) => { };

R
Roman, 2016-10-18
@yarosroman

try-catch doesn't work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question