Update incorrect WebSocket example in Network.md

Using the provided WebSocket example under react-native 0.17, the sample code throws the following error:

"TypeError: ws.on is not a function(…)"

It's listening on ".on" which does not exist, rather than assigning a function to onopen, onmessage, onerror and onclose.

See: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
This commit is contained in:
Hosain 2015-12-25 21:32:39 +00:00 committed by Hosain
parent bde2f30474
commit 70c89fa0d2
1 changed files with 8 additions and 8 deletions

View File

@ -74,25 +74,25 @@ WebSocket is a protocol providing full-duplex communication channels over a sing
```js
var ws = new WebSocket('ws://host.com/path');
ws.on('open', function() {
ws.onopen = () => {
// connection opened
ws.send('something');
});
};
ws.on('message', function(e) {
ws.onmessage = (e) => {
// a message was received
console.log(e.data);
});
};
ws.on('error', function(e) {
ws.onerror = (e) => {
// an error occurred
console.log(e.message);
});
};
ws.on('close', function(e) {
ws.onclose = (e) => {
// connection closed
console.log(e.code, e.reason);
});
};
```
## XMLHttpRequest