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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:23:50+00:00 2026-06-18T11:23:50+00:00

I’ve modified some code from a simple chat tutorial in a very basic way

  • 0

I’ve modified some code from a simple chat tutorial in a very basic way so that I have a JavaScript chatbot sitting on a NodeJS server which immediately sends a response to the client when the user inputs something.

This is the relevant part of the code on the NodeJS server, which works:

socket.on('sendchat', function (data) {
    // we tell the client to execute 'updatechat' with 2 parameters
    io.sockets.emit('updatechat', socket.username, data);
    // we also tell the client to send the bot's response
    io.sockets.emit('updatechat', 'BOT', bot.transform(data));
});

So the bot’s response is very much tied up with the user’s input. I want to now put the bot on a different node server so that the chat can deliver and react to the bot in the same way as it does the user, and so that the bot can process and act independently. Roughly:

USER (client/browser) <---> MEDIATOR (Node server 1) <---> CHAT BOT (Node server 2)

…

I have tried what seemed to me to be the obvious thing to do (which was also obviously wrong), which is take this line from my client:

var socket = io.connect('http://localhost:8080'); // 8080 being the port for the other server

I dropped this into my server-side js file like so:

var app = require('express').createServer();
var io = require('socket.io').listen(app);
app.listen(8080);

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

But this produces an error in the node console to say that the io object has no method connect. Perhaps this is because connect belongs only to the client-side JS script. Is there an easy way for me to have my Node server interact with another Node server without hacking up the client-side library?

More fundamentally, is it even possible to run two node servers at once and have one be a mediator to pass and receive messages from another before pushing to the client? I am using using the Express framework (v2.4.6) and socket.io (v0.8.4), but I’m open to other suggestions.

  • 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-18T11:23:51+00:00Added an answer on June 18, 2026 at 11:23 am

    There are some mistakes in your code. One should use

    io.sockets.on('connection', function (socket) {
    socket.on('updatechat', function(data) {
    ...
    sockets.emit('User',{'user': 'login'});
    sockets.emit('User',{'data': data});
    });
    });
    

    Use socket.emit not io.sockets.emit.
    io.sockets.emit will send to all the clients.
    Also you cannot drop the same line from the client on the server !!!, use the following to connect to another server from node.

    var ioc = require('socket.io-client');         //ioc
    var socket2 = ioc.connect('server2:8080');   //socket2
    

    Rest you can figure out:
    client -> socket -> server -> socket2 -> server2

    Update : socket.io-client is a separate package that needs to be installed for this to work. See here: https://npmjs.org/package/socket.io-client

    Simply do this for installation npm install socket.io-client

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text
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 am doing a simple coin flipping experiment for class that involves flipping a
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
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article

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.