Add @satya164's WebSocket docs from #2839

This commit is contained in:
Martin Konicek 2015-10-07 18:09:18 +01:00
parent 2d7747ecb7
commit c819c5590b
1 changed files with 28 additions and 0 deletions

View File

@ -49,3 +49,31 @@ fetch('https://mywebsite.com/endpoint.php')
console.warn(error);
});
```
## WebSocket
WebSocket is a protocol providing full-duplex communication channels over a single TCP connection.
```javascript
var ws = new WebSocket('ws://host.com/path');
ws.on('open', function() {
// connection opened
ws.send('something');
});
ws.on('message', function(e) {
// a message was received
console.log(e.data);
});
ws.on('error', function(e) {
// an error occurred
console.log(e.message);
});
ws.on('close', function(e) {
// connection closed
console.log(e.code, e.reason);
});
```