3

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

John Nguyen
  • 711
  • 6
  • 21

1 Answers1

0

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(); }

rosst
  • 177
  • 10