Skip to content

How to open multiple clients? #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
exostieStevelo opened this issue May 2, 2018 · 4 comments
Closed

How to open multiple clients? #382

exostieStevelo opened this issue May 2, 2018 · 4 comments
Labels

Comments

@exostieStevelo
Copy link

exostieStevelo commented May 2, 2018

Do you have something example to open multiple clients?

I try something like this:

async def hello(location):
    async with websockets.connect(location) as websocket:
        name = input("What's your name? ")
        await websocket.send(name)
        print("> {}".format(name))

        greeting = await websocket.recv()
        print("< {}".format(greeting))

asyncio.get_event_loop().run_until_complete(hello(locationA))
asyncio.get_event_loop().run_until_complete(hello(locationB))

I will get errors:

error connect Malformed HTTP message
error connect Malformed HTTP message
error connect Malformed HTTP message
error connect Malformed HTTP message
error connect Malformed HTTP message
error connect Malformed HTTP message
error connect Malformed HTTP message
error connect Malformed HTTP message
@aaugustin
Copy link
Member

There isn't enough info here for me to help you.

Your code runs the connections to locationA and locationB one after the other. You don't have multiple clients connected in parallel in this example. So I don't understand what you mean by "multiple clients".

I don't know what locationA and locationB are, but they're probably not a WebSocket server that accepts your connection, because they don't even return a valid HTTP response (based on "Malformed HTTP message" — you didn't say where you were seeing that message).

@exostieStevelo
Copy link
Author

exostieStevelo commented May 3, 2018

@aaugustin thanks you reply. I went clients connected in parallel at the same time.
in this example only one it will be fine.

asyncio.get_event_loop().run_until_complete(hello(locationA))

example:

locationA = 'wss://localhost:443/loga'
locationA = 'wss://localhost:443/logb'

@aaugustin
Copy link
Member

That's really a question about asyncio, not about websockets. Take a look at asyncio.ensure_future or asyncio.wait and related APIs.

(I'm still unsure of how that question is related to the error messages you showed in your original message.)

@exostieStevelo
Copy link
Author

@aaugustin thanks. I will try to dig more about asyncio.

@aaugustin aaugustin mentioned this issue Jun 23, 2019
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants