How to receive log from SRCDS in node.js

Posted on

How to receive log from SRCDS in node.js

I have srcds (source dedicated server)

at console add logaddress_add

this turn on sending the log to the remote server

tried to catch the log in this way

var net = require('net');
var server = net.createServer(function(c) { 
    c.on('end', function() {
        console.log('server disconnected');

and that

var net = require('net');
var client = net.connect({port: 25001});

client.on('data', function(data) {
client.on('end', function() {
    console.log('client disconnected');

and that

var s = dgram.createSocket('udp4');
s.bind(25001, function(data) {

no result. can someone help?

thanks in advance

Solution :


at SRCDS server

logaddress_add //for local ip

at app.js

var dgram = require('dgram'),
    server = dgram.createSocket('udp4');

server.on('message', function (message, rinfo) {
var msg = message.toString('ascii').slice(5,-1);    
server.on('listening', function () {
    var address = server.address();
    console.log('UDP Server listening ' + address.address + ':' + address.port);


I ended up writing a little library to do this (srcds-log-receiver), which validates the packet format, extracts out the date and allows you to use the sv_logsecret function to put a small amount of authentication on the connection, since UDP packets are easily forged.

I also wrote a parser to turn those log lines in to useful objects.

Leave a Reply

Your email address will not be published. Required fields are marked *