Open henopied opened 8 years ago
"µWS
is one of the most lightweight, efficient & scalable WebSocket server implementations available." - I'm interested :+1:
I've tried. Had problems with a compiler or something. Gave up.
The issue is with the sendpacket function.
I don't see what can be causing it. :/
I also tried implementing uws but couldn't get past the sendPacket issue. Maybe @Barbosik can help out or give us a clue?
uws
so much faster
I have found the issue and that is the uws client is not exposed so we cannot add things to its prototype. https://github.com/uWebSockets/uWebSockets/issues/184 edit: I will make a pr once this is resolved
del "WebSocket.prototype.sendPacket"
add ws.sendPacket to function "close"
function close(error) {
this.server.ips[this.socket.remoteAddress] -= 1;
// Log disconnections
this.server.log.onDisconnect(this.socket.remoteAddress);
var client = this.socket.playerTracker;
var len = this.socket.playerTracker.cells.length;
for (var i = 0; i < len; i++) {
var cell = this.socket.playerTracker.cells[i];
if (!cell) {
continue;
}
cell.calcMove = function () {
return;
}; // Clear function so that the cell cant move
this.server.removeNode(cell);
}
client.disconnect = this.server.config.playerDisconnectTime * 20;
this.socket.sendPacket = function () {
return;
}; // Clear function so no packets are sent
if (client.disconnect == -20) {
var index = this.server.clients.indexOf(this.socket)
if (index > -1) {
this.server.clients.splice(index, 1);
}
}
}
ws.sendPacket = function (packet) {
function getBuf(data) {
var array = new Uint8Array(data.buffer || data);
var l = data.byteLength || data.length;
var o = data.byteOffset || 0;
var buffer = new Buffer(l);
for (var i = 0; i < l; i++) {
buffer[i] = array[o + i];
}
return buffer;
}
//if (this.readyState == WebSocket.OPEN && (this._socket.bufferSize == 0) && packet.build) {
if (this.readyState == 1 && packet.build) {
var buf = packet.build();
this.send(getBuf(buf), {
binary : true
});
} else if (!packet.build) {
// Do nothing
} else {
this.readyState = WebSocket.CLOSED;
this.emit('close');
this.removeAllListeners();
}
}
ws.remoteAddress = ws._socket.remoteAddress;
ws.remotePort = ws._socket.remotePort;
this.log.onConnect(ws.remoteAddress); // Log connections
ws.playerTracker = new PlayerTracker(this, ws);
ws.packetHandler = new PacketHandler(this, ws);
ws.on('message', ws.packetHandler.handleMessage.bind(ws.packetHandler));
var bindObject = {
server : this,
socket : ws
};
ws.on('error', close.bind(bindObject));
ws.on('close', close.bind(bindObject));
this.clients.push(ws);
}
^^ That can get us uws?
The above code wouldn't really be ideal.
Could you please try out 0.7.2? I think it should be fixed.
Thanks @henopied and @alexhultman !
Is there a tutorial for windows 10?
@NatsuTheGreat of uws? Nope it doesn't work on Windows currently. There are patches pending to be merged to nodejs which will allow it to work though.
@alexhultman RIP. Going to have to stick with ws
.
@NatsuTheGreat That's up to you. Next Node.js 6.x version will have the patches though.
I am using v6.2.1
@NatsuTheGreat Right, I forgot. It actually already works on 6.3.0 but not with SSL. SSL will come with the next version after 6.3.0.
I am not using SSL, I have an older modified version of MultiOgar. Should I just get 6.3.0?
Should I make a pull request that allows one to choose between uws and ws in the config?
omg yes @henopied please I need uws
@ItzLevvie Oh whoops, silly me!
does it has any advantage against ws?
throw new Error('Compilation of µWebSockets has failed and there is no pre-compiled binary ' +
^
Error: Compilation of µWebSockets has failed and there is no pre-compiled binary available for your system. Please install a supported C++11 compiler and reinstall the module 'uws'.
@NatsuTheGreat I assume you did not read the installation instructions?
Setting it up on windows is confusing me..
I thought Windows support was broken. You need knowledge of C++ or something to use on windows.
It doesn't say that support for windows is broken anymore.
Yes it is very confusing to run:
npm install windows-build-tools npm install uws
especially when this is clearly written in English instructions on the front page under Installation.
Lmao Alex, and what about those compilers you were talking about?
On Windows you need to search the web for pre-compiled binaries or simply compile the dependencies yourself.
Very explanatory. npm install windows-build-tools
Doesn't make a difference as of now.
Installation -> Node.js is your section, not the "native developers" section...
Never mind, clearly I will have to bundle it with pre-built binaries for Windows...
Well lets see, Alex:
npm install --save uws
First of what I see there, and then:
npm install windows-build-tools
I have installed
npm install uws
And
npm install windows-build-tools
Yet the error keeps talking about a C++ Compiler. :/
@alexhultman: does it provide any functionality to minimize impact of DDoS attacks? For example, does it support cloudflare proxy? (there is some issues with headers, so I cannot use ws with cloudflare)
@NatsuTheGreat You did reinstall uws after installing windows-build-tools?
I went in order,
npm install uws npm install windows-build-tools
@NatsuTheGreat That statement does not answer my question, besides - it is the opposite of what the installation instructions tells you to. You need to reinstall uws after installing windows-build-tools.
Okay, sorry. I'll try it now.
Same error. There are also problems with npm install windows-build-tools
You can write in my Gitter.
Oh, I had to run that through Admin CMD Prompt. Python was installed. Waiting for more replies from console.
Write in Gitter, I guess you write npm install --global --production windows-build-tools
@alexhultman vape naysh :+1:
I would like to see
uws
support as it could allow many more clients to connect to multiogar while using less system resources.