-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages. Fixes microsoft#1060
The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages. Fixes microsoft#1060
The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages. Fixes microsoft#1060
Thanks for filing @anttilehtonen. Can you try the fix in PR #1067 and let me know if that solves the problem? |
Thanks for quick fixing! It seems to work, even in my more complex use case. |
@rozele Thanks for quick fixing! It seems to work, even in my more complex use case. |
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. |
The WebSocketModule was missing the `sendBinary` ReactMethod used to support binary messages. Fixes microsoft#1060
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
The text was updated successfully, but these errors were encountered: