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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:50:59+00:00 2026-05-27T20:50:59+00:00

This should be pretty trivial but for whatever reason, I’m having a little trouble

  • 0

This should be pretty trivial but for whatever reason, I’m having a
little trouble connecting ExtJS4 to a socket.io/node.js service (using latest versions from npm and node 0.6.3). I’m trying to send a message to my server. It handshakes but it never gets in the message block. I’m using “emit” to send it from socket.io-client but no luck. Any idea what I’m doing wrong?

I have all my code (forked from Nils Dehl excellent example) and debug out from the server as follows…

I have this code as my server.js:

var http = require('http'),
           sys  = require('util'),
           fs   = require('fs'),
           io   = require('socket.io');
var Connect = require('connect');

var server = Connect.createServer(
        Connect.logger(), // Log responses to the terminal using Common Log Format.
        Connect.staticCache(), // Add a short-term ram-cache to improve performance.
        Connect.profiler(), 
        Connect.favicon(),
        Connect.static(__dirname + "/public") // Serve all static files in the current dir.
);
var sockets = io.listen(server);
server.listen(4000);

sockets.on('connection', function(socket) {
console.log("Receiving msg...");
        var user;

        socket.on('message', function(message) {
                if (!user) {
                        user = message;
                        socket.send({ message: 'Welcome, ' + user.nickname + '!', nickname: 'server', gravatar: '' });
                        return;
                }
                var response = {
                        'nickname': user.nickname,
                        'gravatar': user.gravatar,
                        'message': message.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")
                };
                sockets.emit(response);
        });

});

Then on the client side I’m using ExtJS and socket.io-client to send
the message. My interface in ExtJS looks like this to call into
socket-io.client:

App.util.Socketio = Ext.extend(Ext.util.Observable, { 
        constructor: function(options){ 
                options = options || {}; 
                App.util.Socketio.superclass.constructor.call( 
                        this 
                ); 
                this.socket = new io.Socket(options); 
                var that = this; 
                this.socket.on('connect', function(){ 
                        that.onConnect(); 
                }); 
                this.socket.on('message', function(data){ 
                        that.onMessage(data); 
                }); 
                this.socket.on('close', function(){ 
                        that.onClose(); 
                }); 
                this.socket.on('disconnect', function(){ 
                        that.onDisconnect(); 
                }); 
        }, 
        connect: function() { 
                this.socket.connect(); 
        }, 
        disconnect: function(){ 
                this.socket.disconnect(); 
        }, 
        send: function(message) { 
                this.socket.emit(message); 
        }, 
        onConnect: function() { 
                this.fireEvent('connect'); 
        }, 
        onDisconnect: function() { 
                this.fireEvent('disconnect'); 
        }, 
        onClose: function() { 
                this.fireEvent('close'); 
        }, 
        onMessage: function(message) { 
                this.fireEvent('message', message); 
        } 
}); 

This is what I see for output:

info  - socket.io started 
   debug - client authorized 
   info  - handshake authorized 16300591002012036186 
   debug - client authorized 
   info  - handshake authorized 4532571941614163017 
   debug - setting request GET /socket.io/1/websocket/ 
16300591002012036186 
   debug - set heartbeat interval for client 16300591002012036186 
   debug - client authorized for 
   debug - websocket writing 1:: 
   debug - setting request GET /socket.io/1/websocket/ 
4532571941614163017 
   debug - set heartbeat interval for client 4532571941614163017 
   debug - client authorized for 
   debug - websocket writing 1:: 
   debug - emitting heartbeat for client 16300591002012036186 
   debug - websocket writing 2:: 
   debug - set heartbeat timeout for client 16300591002012036186 
   debug - emitting heartbeat for client 4532571941614163017 
   debug - websocket writing 2:: 
   debug - set heartbeat timeout for client 4532571941614163017 
   debug - got heartbeat packet 
   debug - cleared heartbeat timeout for client 16300591002012036186 
   debug - set heartbeat interval for client 16300591002012036186 
   debug - fired heartbeat timeout for client 4532571941614163017 
   info  - transport end 
   debug - set close timeout for client 4532571941614163017 
   debug - cleared close timeout for client 4532571941614163017 
   debug - discarding transport 
  • 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-27T20:51:00+00:00Added an answer on May 27, 2026 at 8:51 pm

    Two things

    1. Instead of socket.send({ message: 'Welcome, ' + user.nickname + '!', nickname: 'server', gravatar: '' }) change that to socket.emit(hello, { message: 'Welcome, ' + user.nickname + '!', nickname: 'server', gravatar: '' }. You should use emit for sending JSON

      Example – https://github.com/parj/node-websocket-demo/blob/socket_emit/server.js

    2. For socket.emit you need use a custom event – sockets.emit('response', response);

    On the client side for

    1. With reference to – socket.emit(hello, { message: 'Welcome, ' + user.nickname + '!', nickname: 'server', gravatar: '' }

      socket.on('hello', function (data) {
         $('#message').text("Received - " + data.message);
       });
      
    2. With reference to – sockets.emit('response', response);

      socket.on('resonse', function (data) {
         $('#message').text("Received - " + data.response);
       });
      

    socket.send is just for sending a string – Example socket.send("Hello");

    For a full working example on socket.send see – https://github.com/parj/node-websocket-demo
    For socket.emit see – https://github.com/parj/node-websocket-demo/tree/socket_emit/public

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

Sidebar

Related Questions

This seems like it should be pretty trivial, but I am new at Python
I imagine this should be a pretty trivial task but using Firefox for Mac,
This should be pretty simple but for some reason, I can't get this program
This should be pretty straightforward but I'm a little stuck. I have a table
This should be pretty simple but for some reason I can't get this value
This should be pretty simple, but I am new at LINQ. I have a
This feels like it should be pretty simple, but not much seems to be
This seems like it should be pretty straight forward, but I'm apparently confused. I
This should be a pretty trivial one. Can C# return a type that is
I know this should be a pretty elementary issue to fix, but 1) I'm

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.