chensenlai 10988628a0 语音房项目初始化 | hace 5 años | |
---|---|---|
.. | ||
build | hace 5 años | |
src | hace 5 años | |
LICENSE | hace 5 años | |
README.md | hace 5 años | |
binding.gyp | hace 5 años | |
build_log.txt | hace 5 años | |
package.json | hace 5 años | |
uws.js | hace 5 años | |
uws_darwin_46.node | hace 5 años | |
uws_darwin_47.node | hace 5 años | |
uws_darwin_48.node | hace 5 años | |
uws_darwin_51.node | hace 5 años | |
uws_linux_46.node | hace 5 años | |
uws_linux_47.node | hace 5 años | |
uws_linux_48.node | hace 5 años | |
uws_linux_51.node | hace 5 años | |
uws_win32_48.node | hace 5 años | |
uws_win32_51.node | hace 5 años |
uws
tries to mimic ws
as closely as possible without sacrificing too much performance. In most cases you simply swap require('ws')
with require('uws')
:
var WebSocketServer = require('uws').Server;
var wss = new WebSocketServer({ port: 3000 });
function onMessage(message) {
console.log('received: ' + message);
}
wss.on('connection', function(ws) {
ws.on('message', onMessage);
ws.send('something');
});
There are some important incompatibilities with ws
though, we aim to be ~90% compatible but will never implement behavior that is deemed too inefficient:
ArrayBuffer
. This means you need to copy it to keep it past the callback. It also means you need to convert it with Buffer.from(message)
if you expect a Node.js Buffer
.webSocket._socket
is not a net.Socket
, it is just a getter function with very basic functionalities.webSocket._socket.remote...
might fail, you need to cache it at connection.webSocket
acts like an EventEmitter
with one listener per event maximum.webSocket.upgradeReq
is only valid during execution of the connection handler. If you want to keep properties of the upgradeReq for the entire lifetime of the webSocket you better attach that specific property to the webSocket at connection.At installation uws
will try to recompile itself using the system's C++11 compiler (GCC 4.8+, Clang 3.3, VC++ 2015+).
If this fails it will silently fall back to using the precompiled binaries.
NPM installation will never fail but require('uws')
will throw if it cannot properly load the binary module.