pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

Cannot send messages using `reconnecting-websocket` (works with vanilla `WebSocket`) #66

Closed MarcelRobitaille closed 6 years ago

MarcelRobitaille commented 6 years ago

I am so lost. I cannot send messages using this library. Using the browser's WebSocket (as can be seen in the minimal example below), works fine. I am using a simple server configuration to echo all messages received using https://www.npmjs.com/package/ws.

const ws = new ReconnectingWebSocket(`ws://${location.hostname}:5000`)

ws.onopen = () => {
  ws.send('test')
}
// Gives 'test' in node.js console
const ws = new WebSocket(`ws://${location.hostname}:5000`)

ws.onopen = () => {
  ws.send('test')
}
// Nothing in node.js console

I have read through the code and I have no clue why this would be happening. You don't appear to be doing anything fancy with ws.send. Any suggestions?

pladaria commented 6 years ago

I can't reproduce your problem:

Here you have a simple example of reconnecting-websocket sending a message to an echo WebSocket Server and printing the response:

https://codesandbox.io/s/3qj71v8m4m

Could you create a minimal repository where your issue is reproduced?

Thanks!

MarcelRobitaille commented 6 years ago

Interesting. I tried it again (just replaced WebSocket with ReconnectingWebSocket) and everything is working perfectly. Maybe it was fixed in an update? Anyway, thanks for the response and for the project. Great stuff!