pushrax/node-rcon

Unhandled 'error' event

kevinsimper opened this issue · 31 comments

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: connect ECONNREFUSED
    at errnoException (net.js:901:11)
    at Object.afterConnect [as oncomplete] (net.js:892:19)

Tried your example script against a CSGO rcon server, but get this error message.

What is wrong there?

Thanks for the script, it looks awesome. I would not be able to figure out with that buffer and such.

ECONNREFUSED (connection refused) is the generic error for a socket being unable to connect to the host. Try double checking the host and port are correct, and that there isn't a firewall blocking the connection.

Any luck getting this to work, @kevinsimper?

events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect as oncomplete

I also have an error, but on php with rcon_hl_net.inc all works.
I don't know what the problem is..
p.s {
game: cs 1.6
ip: ********
port:27022
rcon_password "test",
need to send a command to the server via node.js, can you help me !?
}

i found the script yet, but there is also a mistake https://bitbucket.org/jyc/rcon.js/src/34d8013fcdc0?at=master
node# node test.js

/../node/rcon.js:7
var {Socket} = java.net;
^
SyntaxError: Unexpected token {

@ecSpl01t I'm not sure why you're asking for support for someone else's library here.

As for your connection refused error, I can't really give you much feedback without seeing the source of the program you're trying to run. Make sure you entered the host and port in the right places.

@pushrax
" I'm not sure why you're asking for support for someone else's library here.", sorry for that.

var Rcon = require('rcon');

var conn = new Rcon('**********', 27022, 'test');
conn.on('auth', function() {
console.log("Authed!");

}).on('response', function(str) {
console.log("Got response: " + str);

}).on('end', function() {
console.log("Socket closed!");
process.exit();

});

conn.connect();

require('keypress')(process.stdin);
process.stdin.setRawMode(true);
process.stdin.resume();

var buffer = "";

process.stdin.on('keypress', function(chunk, key) {
if (key && key.ctrl && (key.name == 'c' || key.name == 'd')) {
conn.disconnect();
return;
}
process.stdout.write(chunk);
if (key && key.name == 'enter') {
conn.send(buffer);
buffer = "";
process.stdout.write("\n");
} else if (key && key.name == 'backspace') {
buffer = buffer.slice(0, -1);
process.stdout.write("\033[K"); // Clear to end of line
} else {
buffer += chunk;
}

});

can you check connection on the server at home ?

@kevinsimper you are fix this problem ?

@pushrax I was trying to connect with other places to servers cs 1.6, servers all different, without success. Maybe a problem in the code (module)?

@ecSpl01t either that server blocks ICMP or it's off, as I can't ping it. When I have a chance I'll take a look at this library again and see if there is a problem with the connection code, although at a glance I really don't see anything.

On my routers set up blocks of anonim ICMP requests. Today i'll open ICMP. The server 95.158.12.226, port 27022 is working without breaks. Thx for your help!

Hm, I can now ping the server but I cannot connect to that port with TCP:

$ telnet 95.158.12.226 27022
Trying 95.158.12.226...
telnet: connect to address 95.158.12.226: Connection refused
telnet: Unable to connect to remote host

I can connect to 80 though:

$ telnet 95.158.12.226 80
Trying 95.158.12.226...
Connected to mail.altme.ru.
Escape character is '^]'.
GET /
<!DOCTYPE HTML>
<html>
<head>
...

Just did a quick search online: apparently HLDS uses UDP for rcon. This script was developed for TCP rcon servers, so it'll need a modification to work with HLDS. I'll have some time on Thursday to do so.

root@mail# telnet 95.158.12.226 27023
Trying 95.158.12.226...
telnet: Unable to connect to remote host: Connection refused
root@mail# telnet 192.168.1.132 27001
Trying 192.168.1.132...
telnet: Unable to connect to remote host: Connection refused
root@mail# telnet 192.168.1.132 27002
Trying 192.168.1.132...
telnet: Unable to connect to remote host: Connection refused
root@mail# telnet 192.168.1.132 27003
Trying 192.168.1.132...
telnet: Unable to connect to remote host: Connection refused
root@mail# telnet 192.168.1.132 27004
Trying 192.168.1.132...
telnet: Unable to connect to remote host: Connection refused
root@mail# telnet 192.168.1.132 27005
Trying 192.168.1.132...
telnet: Unable to connect to remote host: Connection refused
root@mail# telnet 192.168.1.132 27006
Trying 192.168.1.132...
telnet: Unable to connect to remote host: Connection refused
root@mail# telnet 192.168.1.132 27030
Trying 192.168.1.132...
Connected to 192.168.1.132.
Escape character is '^]'.

27001-27007, 27022 and 27023, game CS 1.6.
27030 - game CS:GO

i'll wait, thx...

@ecSpl01t I added some initial UDP support. Try running against the current master.

You can enable UDP like so:

var conn = new Rcon('95.158.12.226', 27022, 'test', { tcp: false });

@pushrax, thank you ever so much!

Super cool! Thanks, did not know that, will try that tommorow.

@kevinsimper Well, CS:GO should have worked fine all along, as all Source games use the TCP RCON protocol. Turning on UDP for CS:GO would actually cause it to break. Try out the library as TCP again though, and let me know how it goes!

@ecSpl01t How's it working for you? I just published v0.2.0, and I'm hoping the UDP implementation isn't buggy since I'm not using it myself.

@pushrax How to send full packet ? i've data:
conn.send("say 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
but only get it, on server: 123456789012345678901234567890123456789012345678901234567890123

@pushrax i can't to send command on the server before "Socket closed!" i need to send command
.on('end', function() {
conn.send("say "+info);
console.log("Socket closed!");
process.exit();
})

dgram.js:417
throw new Error('Not running'); // error message from dgram_legacy.js
^
Error: Not running
at Socket._healthCheck (dgram.js:417:11)
at Socket.send (dgram.js:269:8)
at Rcon._sendSocket (./connect_module.js:77:21)
at Rcon.send (./connect_module.js:70:8)
at Rcon. (./connect_server.js:17:10)
at Rcon.EventEmitter.emit (events.js:92:17)
at Rcon.socketOnEnd (./connect_module.js:196:8)
at Socket. (./connect_module.js:95:51)
at Socket.EventEmitter.emit (events.js:92:17)
at Socket.close (dgram.js:328:8)

@ecSpl01t for that last issue, it looks like you're trying to send data within the end event handler. When this event is fired, the socket has already closed.

As for the issue with truncation, I'm fairly sure the correct way to handle it is by splitting outgoing packets, but as I can't find any information on the protocol for this I can't implement it right away. I'll need to take a look at a packet dump of an rcon session for a real client to figure this one out.

@pushrax i've a problem with .on ('response', function (str) {
     console.log ("Got response:" + str);
   })
answers come from other servers ..i run the server using the screen

Right, I hardcoded the port. Give me a few minutes and I'll fix that.

edit: fixed in f164b7a

"for that last issue, it looks like you're trying to send data within the end event handler. When this event is fired, the socket has already closed." thx, i done that

sometimes doesn't send the data to the server, then I just reboot script, can this be the problem was in the "f164b7a" ?

Man, UDP is so ghetto. Theoretically, passing port 0 should tell the OS to pick a currently unused port, so I'm not sure why it would fail. If I have time soon I'll look into this, but for now I guess just pick a random port that doesn't fail to bind?

@pushrax I didn't understand what the problem is, why there is "Bad challenge." http://plasmon.rghost.ru/50184653/image.png

@ecSpl01t What game is that happening with?

Counter-strike 1.6
did you look about sending of full package ?

I don't have enough context to actually consider this issue to still be open. Feel free to create a new issue if there is one.