简体   繁体   中英

How to disconnect from socketio4net

I have a application that connecting from c# client to node.js server in c# client I am using socketio4net and websocket4net in server I using nodejs and socket.io

when I close my program (c#), disconnect event was not sent to server. so I got error:

socket error Error: read ECONNRESET at errnoExeption (net.js: 558:19)

but if i am using socket.io client (javascript) instead of c# when I close browser, everything work well this is my code:

server.js:

var io= require('socket.io').listen(3000);
io.on('connection', function (socket) {  
    socket.on('disconnect', function () {
    // handle here
    })
})

c# client:

client = new Client("http://127.0.0.1:3000/");
socket = client.Connect();

javascript client:

io.connect("127.0.0.1:3000");

Can anyone please help me? Thanks very much

This is clearly an old question, but I actually had this issue yesterday so I might as well post it. Solution was to create an event for onClose of the program and call socket.Close().

For me, I'm using WPF so in my xaml:

<Window x:Class="Example.MainWindow" ... Closing="Window_Closing">

And in code behind:

private void Window_Closing(object sender, CancelEventArgs e) { socket.Close(); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM