Skip to content
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

Sending to a specific client #66

Open
Jawmo opened this issue Oct 11, 2018 · 6 comments
Open

Sending to a specific client #66

Jawmo opened this issue Oct 11, 2018 · 6 comments

Comments

@Jawmo
Copy link

Jawmo commented Oct 11, 2018

I noticed that you have instructions to send to a specific client, but when I print our the value of "client", I just get back the current user's information. If I have to use "client" when I use send_message(), how do I actually specify the client ID?

I have to use: send_message(client, "message here.)

If I change "client" to "client['id']" or something, it won't work. How do you actually specify which use it should go to?

@DavidSteinmann
Copy link

DavidSteinmann commented Aug 13, 2020

I just do a for loop looping over all the clients and selecting only the one i want. Here's my function:

def sendMessageToClient(name, message):
	targetClient = None
	for oneClient in server.clients:
		if oneClient['id'] == name:
			targetClient = oneClient
			break
	if targetClient is not None:
		server.send_message(targetClient, message)

Hope it helps

@Pithikos
Copy link
Owner

This is a bad design decision at the time - using a list instead of a dict.

The workaround is to loop through the clients and once you find your client, use the handler handler.send_text

@TheTechRobo
Copy link

TheTechRobo commented Oct 10, 2022

Maybe there should be a server.clients_dict or something (in addition to the existing, to keep compatibility)?

@Pithikos
Copy link
Owner

Maybe there should be a server.clients_dict or something (in addition to the existing, to keep compatibility)?

Yes, probably a clients_by_id with client ID as key. But not something I have the time currently to work on unfortunately

@TheTechRobo
Copy link

I might pick this up. Shouldn't be too difficult.

@AsgJeold
Copy link

I just do a for loop looping over all the clients and selecting only the one i want. Here's my function:

def sendMessageToClient(name, message):
	targetClient = None
	for oneClient in server.clients:
		if oneClient['id'] == name:
			targetClient = oneClient
			break
	if targetClient is not None:
		server.send_message(targetClient, message)

Hope it helps

Thanks for that. It helped me to solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants