Created
July 7, 2015 22:13
-
-
Save nemtsov/a4a1c7c2627bd09114b1 to your computer and use it in GitHub Desktop.
UDP & Redis Client / Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dgram = require('dgram'); | |
var client = dgram.createSocket('udp4'); | |
var message = new Buffer('Hello world!'); | |
client.send(message, 0, message.length, 9999, 'localhost', function (err) { | |
if (err) return console.error(err); | |
console.log('message sent'); | |
client.close(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dgram = require('dgram'); | |
var redis = require('redis'); | |
var server = dgram.createSocket('udp4'); | |
var redisClient = redis.createClient(); | |
var ctr = 0; | |
server.on('message', function (msg) { | |
console.log('server received msg:', msg.toString()); | |
redisClient.set('udp:message:' + ctr++, ctr, redis.print); | |
}); | |
server.bind(9999, function () { | |
console.log('listening...'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment