Answer the question
In order to leave comments, you need to log in
Why does React get an error when trying to connect a websocket from C# code?
Good afternoon, comrades! I'm still new to React, and I can't figure out why this code doesn't work as it should.
componentDidMount = () => {
this.ws = new WebSocket('ws://localhost:3000/ws');
this.ws.addEventListener('message', function(e) {console.log('Server: ' + e.data);})
}
using (var ws = new WebSocket("ws://localhost:3000/ws"))
{
ws.OnMessage += (sender, e) =>
Console.WriteLine("Laputa says: " + e.Data);
ws.Connect();
ws.Send("BALUS");
Console.ReadKey(true);
}
websocket.js:80 WebSocket connection to 'ws://localhost:3000/sockjs-node/256/ixu2w3gz/websocket' failed: WebSocket is closed before the connection is established.
WebSocket connection to 'ws://localhost:3000/ws' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
POST http://localhost:3000/sockjs-node/256/e4o5pyqd/xhr_streaming?t=1545998206736 net::ERR_CONNECTION_RESET 200 (OK)
The development server has disconnected.
Refresh the page if necessary.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question