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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:14:11+00:00 2026-05-25T01:14:11+00:00

Can I open two WebSocket connections to one server but two different ports from

  • 0

Can I open two WebSocket connections to one server but two different ports from one html page.

I’ve searched in google but couldn’t find anything useful. And also can you give me links to some tutorials for web sockets. These are the ones i found:

http://websocket.org/echo.html

http://www.html5rocks.com/en/tutorials/websockets/basics/

  • 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-25T01:14:12+00:00Added an answer on May 25, 2026 at 1:14 am

    Would this not work?

    var socket1 = new WebSocket('ws://localhost:1001');
    var socket2 = new WebSocket('ws://localhost:1002');
    

    As for how your server handles it, it would very much depend on your server side technology.

    For tutorials, the client-side aspect of WebSockets is dead easy, this is pretty much it:

    var socket;
    
    // Firefox uses a vendor prefix
    if (typeof(MozWebSocket) != 'undefined') {
        socket = new MozWebSocket('ws://localhost');
    }
    else if (typeof(WebSocket) != 'undefined') {
        socket = new WebSocket('ws://localhost');
    }
    
    if (socket != null) {
        socket.onmessage = function(event) {
            // fired when a message is received from the server
            alert(event.data);
        };
    
        socket.onclose = function() {
            // fired when the socket gets closed
        };
    
        socket.onerror = function(event) {
            // fired when there's been a socket error
        };
    
        socket.onopen = function() {
            // fired when a socket connection is established with the server,
            // Note: we can now send messages at this point
    
            // sending a simple string to the server
            socket.send('Hello world');
    
            // sending a more complex object to the server
            var command = {
                action: 'Message',
                time: new Date().toString(),
                message: 'Hello world'
            };
            socket.send(JSON.stringify(command));
        };
    }
    else {
        alert('WebSockets are not supported by your browser');
    }
    

    The server-side aspect of how to handle incoming WebSocket connections is a lot more complex, and varies depending on your server-side technology (ASP.NET, PHP, Node.js etc.).

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

Sidebar

Related Questions

Access can open DBF (dBase) files, but instead of physically converting the data into
I realise that you can open the google maps app ready for directions by
I would like to know if I can open 2 different diagrams using MS
[DllImport(kernel32.dll)] private static extern Int32 AllocConsole(); I can open cmd.exe with this command. But
I have two sortable lists that are connected. One is simply on the page,
I'm trying to open and read from a serial port using the System.IO.Ports.SerialPort class.
Can I open the same file twice (with CreateFileA ), using different flags (in
I have tried on two different machines, and tried the download several times, but
If you open two versions of my site in two different tabs, go to
I saw in another Stack Overflow post you can open the Google maps application

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.