Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket with binary data doesn't seem to work #1060

Closed
anttilehtonen opened this issue Mar 9, 2017 · 4 comments
Closed

websocket with binary data doesn't seem to work #1060

anttilehtonen opened this issue Mar 9, 2017 · 4 comments
Assignees

Comments

@anttilehtonen
Copy link

Hello,
I try to send array buffers over the socket to react-native client.
In Android emulator this works but in Windows emulator it doesn't work but it closes the socket.
I am using "react-native-windows": "^0.42.0-rc.5" and application has been created with 'react-native init websockettest' command.
I am using Node JS ws module to implement simple server.
Attached are zip files for client code without ios, android and windows folders and server side code.

console.log prints error when I send array buffer from the server and connection closes.
In Android the same code works as expected.

snippet of console.log:

In Windows:
1489057053027 "opened"
1489057053030 "message" "hello from server"
1489057053033 "error" WebSocketEvent {type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false…}
1489057053036 "closed"

In Android:
1489056911160 "opened"
1489056911223 "message" "hello from server"
1489056911228 "message" ArrayBuffer {}

server side code:

const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 3141 });

wss.on('connection', function connection(ws) {
console.log((new Date()).getTime(), 'connected');
ws.on('message', function incoming(message) {
console.log('received message react-native', message);
});
ws.send('hello from server');

const buf = new ArrayBuffer(400);
const a = new Uint8Array(buf);
for(let i=0; i<a.length; i++) a[i] = i % 256;
ws.send(buf);

});

client side code:

const start = () => {
const socket = new WebSocket('ws://a.b.c.d:3141');
socket.binaryType = 'arraybuffer';

socket.addEventListener('message', (message) => {
console.log((new Date()).getTime(), 'message', message.data);
});
socket.addEventListener('open', (event) => {
console.log((new Date()).getTime(), 'opened');
});
socket.addEventListener('close', (event) => {
console.log((new Date()).getTime(), 'closed');
});
socket.addEventListener('error', (error) => {
console.log((new Date()).getTime(), 'error', error);
});
}

export default start;

websockettest.zip
websocketserver.zip

rozele added a commit to rozele/react-native-windows that referenced this issue Mar 10, 2017
The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages.

Fixes microsoft#1060
rozele added a commit to rozele/react-native-windows that referenced this issue Mar 10, 2017
The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages.

Fixes microsoft#1060
rozele added a commit to rozele/react-native-windows that referenced this issue Mar 10, 2017
The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages.

Fixes microsoft#1060
@rozele
Copy link
Collaborator

rozele commented Mar 10, 2017

Thanks for filing @anttilehtonen. Can you try the fix in PR #1067 and let me know if that solves the problem?

@rozele rozele self-assigned this Mar 10, 2017
@anttilehtonen
Copy link
Author

Thanks for quick fixing! It seems to work, even in my more complex use case.
Any idea when we get official fix?

@anttilehtonen
Copy link
Author

@rozele Thanks for quick fixing! It seems to work, even in my more complex use case.
Any idea when we get official fix?

@matthargett
Copy link
Contributor

Fixed in #1067. I'll cherry pick to 42-stable branch and publish it there, then publish it in a new 43-stable package as well.

rozele added a commit to rozele/react-native-windows that referenced this issue May 22, 2017
The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages.

Fixes microsoft#1060
rozele added a commit that referenced this issue May 23, 2017
…#1067)

The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages.

Fixes #1060
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants