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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:20:46+00:00 2026-06-09T12:20:46+00:00

I would write a websocket client in python to connect to a server written

  • 0

I would write a websocket client in python to connect to a server written with socket.io.
My current code, taken from 1 is the following:

import websocket, httplib, sys, asyncore
def connect(server, port):

    print("connecting to: %s:%d" %(server, port))

    conn  = httplib.HTTPConnection(server + ":" + str(port))
    conn.request('POST','/socket.io/1/')
    resp  = conn.getresponse() 
    hskey = resp.read().split(':')[0]
    ws = websocket.WebSocket(
                'ws://'+server+':'+str(port)+'/socket.io/1/websocket/'+hskey,
                onopen   = _onopen,
                onmessage = _onmessage,
                onclose = _onclose)

    return ws

def _onopen():
    print("opened!")

def _onmessage(msg):
    print("msg: " + str(msg))

def _onclose():
    print("closed!")


if __name__ == '__main__':

    server = 'localhost'
    port = 8081

    ws = connect(server, port)

    try:
        asyncore.loop()
    except KeyboardInterrupt:
        ws.close()

My question is how do I connect to a specific namespace?

Thanks

  • 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-09T12:20:48+00:00Added an answer on June 9, 2026 at 12:20 pm

    You can use socketIO-client which is available on PyPI under the MIT license. It has support for different namespaces of a single socket.

    from socketIO_client import SocketIO, BaseNamespace
    
    class MainNamespace(BaseNamespace):
    
        def on_aaa(self, *args):
            print 'aaa', args
    
    class ChatNamespace(BaseNamespace):
    
        def on_bbb(self, *args):
            print 'bbb', args
    
    class NewsNamespace(BaseNamespace):
    
        def on_ccc(self, *args):
            print 'ccc', args
    
    mainSocket = SocketIO('localhost', 8000, MainNamespace)
    chatSocket = mainSocket.connect('/chat', ChatNamespace)
    newsSocket = mainSocket.connect('/news', NewsNamespace)
    mainSocket.wait()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I write the following C# code in F#? namespace Shared { public
To check whether value is numeric in LS, I would write the following code:
By following example from em-websocket gem, I've just create simple echo-server that running with
I have to write simple client-server application that uses Unix datagram socket. Client may
How would one write a sql server DDL script that can: For each table
How would I write a SQLite query to select all records from a specific
So, In my old Linq-To-SQL I would write code like this var tableItem =
I want to write a server for a browser-based MMO game, which uses WebSocket
I thought I would write some quick code to download the number of fans
I'm coming from a C# background where I would write a class and constructor

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.