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 6068501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:43:18+00:00 2026-05-23T09:43:18+00:00

Ok trying my hand at NodeJS and socket.io and have run into a problem.

  • 0

Ok trying my hand at NodeJS and socket.io and have run into a problem. I have NodeJS and Socket.io installed and running on my localhost. At present I have the following setup:

server.js

// Require HTTP module (to start server) and Socket.IO
var http = require('http'), io = require('socket.io');

// Start the server at port 8080
var server = http.createServer(function(req, res){ 

// Send HTML headers and message
  res.writeHead(200,{ 'Content-Type': 'text/html' }); 
  res.end('<h1>NodeJS Server Online</h1>');
});
server.listen(8080);

// Create a Socket.IO instance, passing it our server
var socketserver = io.listen(server);

// Add a connect listener
socketserver.on('connection', function(socket){ 

    socket.emit("server ready");

    socket.on('test', function (msg) {
        socket.broadcast.emit('TEST:', msg);
        console.log(msg);
    });

    socket.on('user message', function (msg) {
        socket.broadcast.emit('user message', msg);
        console.log(msg);
    });

});

client.js

$(document).ready(function() {
// Stuff to do as soon as the DOM is ready;
    var socket =  io.connect('http://localhost',{port:8080});

    socket.on('server ready',function() {
        messages.append("<li>Server Ready...</li>");
        console.log("Server Ready");
    });

    // Add a connect listener
    socket.on('connect',function() {
        messages.append("<li>Connected...</li>");
        console.log("connected");
        socket.emit('test',"Just testing");
    });

});

Server starts fine, but my problem is that the server.js does not fire the socket.emit(“server ready”); line. The client side code works fine as in terminal.app on testing my server outputs this line:

websocket received data packet 5:::{"name":"test","args":["Just testing"]}

What am I missing? Why isn’t the server side stuff firing?

  • 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-05-23T09:43:18+00:00Added an answer on May 23, 2026 at 9:43 am

    I updated socket.io to 0.7.2 and then slightly modified your example to use express. The code below was able to receive the “server ready” event.

    Node Server:

    var http = require('http'),  
        express = require('express');
    
    var app = module.exports = express.createServer();
    
    // Configuration
    
    app.configure(function(){
      app.use(express.static(__dirname + '/public'));
    });
    
    app.listen(9000);
    console.log("server started");
    
    // socket.io 
    var io = require('socket.io').listen(app);
    
    io.sockets.on('connection', function(socket){ 
        socket.emit('server ready', {msg: 'hi'}) ;
    }); 
    

    Web Page (/sock.html):

    <html>
    <body>
    <script type="text/javascript" src="/socket.io/socket.io.js"></script>
    <script> 
    var socket = io.connect();
    socket.on('server ready', function(data){ console.log('server ready!'); }) ;
    </script> 
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying my hand at java and android and have run into a problem which
I'm trying to run a particular JUnit test by hand on a Windows XP
Trying to setup an SSH server on Windows Server 2003. What are some good
i'm trying my hand with PDO and would like to know if the following
I've been trying my hand at OO PHP, and currently have three files. I
I'm trying my hand at Euler Problem 4 in Haskell. It asks for that
recently I have been trying my hand at coding a game in C#. I'm
I've been trying my hand at optimising some code I have using microsoft's sse
I have been trying my hand at creating a remote shell in C for
I'm trying my new hand at Code Igniter and have this issue come up.

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.