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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:49:29+00:00 2026-06-01T00:49:29+00:00

I am working with socket.io and express, and I am struggling with having unique

  • 0

I am working with socket.io and express, and I am struggling with having unique pages that all send and recieve messages from the server.

When I follow most tutorials, the server script starts out with something like this:

var app = require('express').createServer()
var io = require('socket.io').listen(app);
var clients = {};

app.listen(8080);

// routing
app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

and I can test my client app at localhost:8080. But what I want is to run a multiple client apps at something like http://localhost:8080/myApp/client1.html and http://localhost:8080/myApp/client2.html. When I try this, it returns something like:

Cannot GET /myApp/client1.html

My goal is to have two or more unique pages that can send messages to each other via sockets. Any help is greatly appreciated. I have been banging my head on this for way too long now.

  • 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-01T00:49:30+00:00Added an answer on June 1, 2026 at 12:49 am

    I’m not very familiar with Express but instinct tells me get() would refer to a GET HTTP request and thus not a websocket. I think you’re supposed to use Express to return HTML for page requests but real-time data transfer would be handled by Socket.io.

    So, you would have Express return for the actual page requests:

    app.get('/myApp/client1.html', function(blah){});
    app.get('/myApp/client2.html', function(blah){});
    

    Then socket.io would handle the talking:

    var io = require('socket.io').listen(app);
    
    io.sockets.on('connection', function (socket) {
      socket.on('msg', function (data) {
        io.sockets.emit('msg', {msg: data.msg});
      });
    });
    

    Client:

    var socket = io.connect('http://localhost:8080');
    socket.on('msg', function (data) {
      //code to add data.msg somewhere on page
    });
    somebutton.on('click', function(e){
      socket.emit('msg', {msg:$(e.targetElement).value()});
    });
    

    Again, I don’t know Express so I may have the syntax wrong but my gist is that you have two things going on that you need to handle separately. One is the returning of actual HTML pages, the other is the real-time data communication between the loaded pages. My examples are crude, check the Socket.io Readme for some better examples.

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

Sidebar

Related Questions

I'm working on a project for my company that uses a socket server (php)
I am working with Node.js to build a web socket server that uses mongodb.
for some reason my server that uses socket.io is not working properly. The program
I'm having issues getting a simple server/client socket app working in C# between two
I've been working with socket programming lately; and I'm currently making a server that
I'm working on a project involving Socket.IO that I'd like to add encryption to.
I had my server working with an earlier version of node.js, npm, and socket.io
I am working on a server application which receives data over a TCP socket
I'm working on a flash application that needs to communicate with my C++ server
I'm working on a socket based client-server app. When a user running any iDevice

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.