Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Ping Server & Client UDP socket
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
510carlos  
View profile  
 More options Nov 12 2012, 2:48 pm
From: 510carlos <carlos.mendoza...@gmail.com>
Date: Mon, 12 Nov 2012 11:48:15 -0800 (PST)
Local: Mon, Nov 12 2012 2:48 pm
Subject: Ping Server & Client UDP socket

I am attempting to create a small ping for proof of concept. I am just
learning node.js. I want the client to send a packet over UDP. The server
should acknowledge it by writing to console and send another packet of the
the same size back to the client.

This is what I have so far.:

Server:

var PORT = 33333;
var HOST = '127.0.0.1';

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

server.on('listening', function () {
    var address = server.address();
    console.log('UDP Server listening on ' + address.address + ":" +
address.port);

});

server.on('message', function (message, remote) {

    console.log(remote.address + ':' + remote.port +' - ' + message);
    // I was put a server.send here but it gives me an infinite loop.

});

server.bind(PORT, HOST);

Client:
var PORT = 33333;
var HOST = '127.0.0.1';

var dgram = require('dgram');
var message = new Buffer('My KungFu is Good!');

var client = dgram.createSocket('udp4');

var count = 0;

client.on('message', function (message, remote) {

    console.log(12);

});

client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {
    if (err) throw err;
    console.log('UDP message sent to ' + HOST +':'+ PORT);
    count++;

});

Can you guys help me out?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »