Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8521453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:49:46+00:00 2026-06-11T06:49:46+00:00

I’m new to the node.js and socket.io scene, so this may be a simple

  • 0

I’m new to the node.js and socket.io scene, so this may be a simple fix… but here goes. I have the following POC for taking in messages via UDP and echoing them back to a browser. UDP messages are received on 55555, a websocket write is performed, and the client sees the data in their browser. However, the moment another client connects to the server, four websocket writes are performed when a datagram is received – two to each client I believe, as the appended data now shows up twice. Firing up a third client shows six websocket writes – appended data appears three times now.

Any ideas what is causing this? Dumb error? Misinterpretation? Bug?

server:

var dgram = require("dgram");
var udpserver = dgram.createSocket("udp4");
udpserver.bind(55555);  //udp listener

var express = require("express");
var app = express();
var http = require('http');
var server = http.createServer(app);
var io = require('socket.io').listen(server);
server.listen(12345);  //tcp http listener

io.sockets.on('connection', function (socket) {
    udpserver.on('message', function (msg, rinfo) {
            io.sockets.emit('update', msg.toString());
    });
});

client:

<!DOCTYPE HTML>
<script src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script src="http://localhost:12345/socket.io/socket.io.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        var socket = new io.connect('http://localhost:12345');
        socket.on('update', function (data) {
            $("#stuff").append(data + "<br>");
        });
     });
</script>
<div id=stuff></div>
</html>

Here’s some node output showing data sent after the first client connects, and after a second one connects:

info  - socket.io started
debug - served static content /socket.io.js
debug - client authorized
info  - handshake authorized xrMZtzv9HPSngRYzMibw
debug - setting request GET /socket.io/1/websocket/xrMZtzv9HPSngRYzMibw
debug - set heartbeat interval for client xrMZtzv9HPSngRYzMibw
debug - client authorized for
debug - websocket writing 1::
debug - websocket writing 5:::{"name":"update","args":["test1\n"]}
debug - emitting heartbeat for client xrMZtzv9HPSngRYzMibw
debug - websocket writing 2::
debug - set heartbeat timeout for client xrMZtzv9HPSngRYzMibw
debug - got heartbeat packet
debug - cleared heartbeat timeout for client xrMZtzv9HPSngRYzMibw
debug - set heartbeat interval for client xrMZtzv9HPSngRYzMibw
debug - served static content /socket.io.js
debug - client authorized
info  - handshake authorized VJKxI4y8TV9tcYjEMibx
debug - setting request GET /socket.io/1/websocket/VJKxI4y8TV9tcYjEMibx
debug - set heartbeat interval for client VJKxI4y8TV9tcYjEMibx
debug - client authorized for
debug - websocket writing 1::
debug - websocket writing 5:::{"name":"update","args":["test1\n"]}
debug - websocket writing 5:::{"name":"update","args":["test1\n"]}
debug - websocket writing 5:::{"name":"update","args":["test1\n"]}
debug - websocket writing 5:::{"name":"update","args":["test1\n"]}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:49:48+00:00Added an answer on June 11, 2026 at 6:49 am

    As far as I can tell without having node to test on; you’re not really interested in doing anything on socket.io connection events as long as the client doesn’t send any data you need to handle, so you should be able to ignore them. What you want is only to receive UDP events and broadcast to all clients that are connected right then, which should be as simple as;

    ...
    var io = require('socket.io').listen(server);
    server.listen(12345);  //tcp http listener
    
    udpserver.on('message', function (msg, rinfo) {
        io.sockets.emit('update', msg.toString());
    });
    

    Just for completeness; what your current code does is to add a new UDP message callback for every new socket.io connection. The callback broadcasts to all clients, which means that when the second client connects, all broadcasts will happen 2 times to all clients, for 3 clients 3 times to all clients etc. You only want to set the UDP message handler up once since it broadcasts to all connected clients anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.