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

  • Home
  • SEARCH
  • 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 6716441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:44:03+00:00 2026-05-26T08:44:03+00:00

Hello I am trying to use python’s pywebsocket HTML5 server, where i use the

  • 0

Hello I am trying to use python’s pywebsocket HTML5 server, where i use the given example file which echos back whatever is received.

def web_socket_transfer_data(request):
    count = 0
    while (count < 1):
    line = request.ws_stream.receive_message()
    print line
    request.ws_stream.send_message(line)  

It works fine with one webpage, but if i use two clients (two webpages connection to the same socket server over same ports), the script works the same.

What i am trying to do is to have those messages broadcasted by the socket server of for any message echoed back, should be listened by both cient webpages. But unforutnally it does not work. I am confused as both pages are listening over same socket, then why is it not working.

Is there any workaround or modification i need to do so that i can make the socket server transfer message or broadcast to all its connected clients.

Please help…

  • 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-26T08:44:03+00:00Added an answer on May 26, 2026 at 8:44 am

    With the exception of multicast sockets, all are 1:1 connections. You have to maintain the list of open sockets somewhere, and send the message to each of them. The port you connect to when creating the socket being the same merely means each client is connected to the same service.

    Here’s how you might add each connection to a list and broadcast to all of them. Of course, I’d strongly recommend having code to handle dead and/or closed connections and remove them from the list as well, I’m just going for the general idea here (especially since I haven’t coded in Python for a few years. I based this code snippet on the pywbsocket example code, which is why it’s different from yours. Note that I haven’t considered thread safety at all either, which should be a concern)

    connections = []
    
    def web_socket_do_extra_handshake(request):
        connections.append(request);
        pass
    
    def web_socket_transfer_data(request):
        while True:
            line = msgutil.receive_message(request)
            for connection in connections[:]:
                msgutil.send_message(connection, line)
            if line == "Bye":
                return
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just trying to compile the hello world example of boost.python WITHOUT using all
I'm trying to use lua for windows - SciTE Simply example such as Print(hello)
I'm trying Heroku with Python, I ran the hello word example with Flask successfully.
I'm trying to use Python's @property decorator on a dict in a class. The
I am trying to use gmail's SMTP server smtp.gmail.com to send mails using C
Hello i am trying to do a dictionary by using Python, What needs to
I'm trying to use Boost.Python as a wrapper for a C++ function that receives
I'm trying to use groovyc, but something is not right: >echo println(Hello world) >
I'm trying to use Python's ctypes to work with a DLL, but I occasionally
I'm trying to use pygtk in Python but when I try running my code

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.