Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

node.js and socket.io

node.js and socket.io

Problem

I have created a small Server for communication using node.js and socket io

Server:

var express = require('/usr/local/lib/node_modules/express')
var io = require('/usr/local/lib/node_modules/socket.io');
var server = express.createServer();
server.listen(8888,'localhost');
io = io.listen(server);
io.of("namespace").on('connection', function(client){
     client.emit("message",'connection successful');
     client.on('message', function(m){
        console.log("received message"+m);
         client.broadcast(m);
     });
});

Client:



    Comet Test

publish customAlert

publish customAl

Communication does not happen, am I doing something wrong here?

Problem courtesy of: user160108

Solution

If your server is listening on port 8888, you need the client to connect to the server on port 8888.

The following line in your client code:

var socket = io.connect('http://localhost/namespace');

Should read:

 var socket = io.connect('http://localhost:8888/namespace');
Solution courtesy of: fourk

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

node.js and socket.io

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×