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

  • Home
  • SEARCH
  • 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 8461235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:49:27+00:00 2026-06-10T13:49:27+00:00

I am new to socket.io and i am trying out the examples mentioned on

  • 0

I am new to socket.io and i am trying out the examples mentioned on their site. I am going good with it but problem occurs when i try to use io.emit on the server side and try to receive on client side.

Here is my server code

var io=require("socket.io").listen(8888);
io.set('log level',1);
io.on('connection',function(socket){ 
socket.emit('hi');
console.log("Connected");
});

And my client’s code

<script src="http://localhost:8888/socket.io/socket.io.js"></script>
<script>
var socket=io.connect("http://localhost:8888");
socket.set('log_level',1);
socket.on('hi',function(){
console.log('received');
});
</script>

The problem is i don’t see the message ‘received’ in the console! The answer may be trivial but i tried experimenting but failed everytime. Please guide….

I am on ubuntu firefox. node version: 0.8.7

  • 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-10T13:49:29+00:00Added an answer on June 10, 2026 at 1:49 pm

    So you should have this on the serve side:

    var io = require('socket.io').listen(88888);
    io.set('log level',1);
    io.sockets.on('connection', function (socket) {
      socket.emit('hi);
      console.log("Connected");
      });
    });
    

    And you should have this on the client side:

    <script src="http://localhost:8888/socket.io/socket.io.js"></script>
    <script>
      var socket = io.connect('http://localhost:8888/');
      socket.set('log_level',1);
      socket.on('hi', function () {
        console.log(data);
        socket.emit('my other event', { my: 'data' });
      });
    </script>
    

    WebSockets like many html5 features does not work in a non webserver environment. I mean It won’t work if you are accessing your client with the file protocol.
    You need to have a http server.
    What I do to get things done easily, I use python built-in web-server. It does the job.
    Just spawn it in you client folder like this:

    python -m SimpleHTTPServer
    

    And then point your browser to port 8000 (default).

    I’ve made a boiler plate socket.io app that you can clone and even push directly to dotCloud.com
    This is a simple example and could help you to get started with socket.io.

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

Sidebar

Related Questions

I am new to socket programming and I'm trying to figure out how poll
I'm new to boost and I've been trying out boost::asio. The problem is I
Im trying out the new additions of Socket-communication (TCP & UDP) in the Beta
I'm trying to use the new Socket API for Chrome extensions, and I'm encountering
I am trying to create a new TCP socket in Android emulator. Below is
When creating a Socket in Java: new Socket(host, port); The Socket constructor will try
I'm very very new to programming in Python, but out of necessity I had
I'm trying to use Moles to mock the Socket class in System.Net.Sockets. I have
I have been banging my head trying to figure out what is going wrong.
I'm trying to open a socket to a website over the Internet, but can't.

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.