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

SendText #70

Closed
gpspelle opened this issue Apr 1, 2020 · 4 comments
Closed

SendText #70

gpspelle opened this issue Apr 1, 2020 · 4 comments

Comments

@gpspelle
Copy link

gpspelle commented Apr 1, 2020

Hi,

After reading this incredible Library, I am not sure yet about the send message process. As far as I understood, the example that you gave in your main.py file, you send a reply whenever you have received a message. But how should I do to send a message even I didn't get a message in the first place?

Thanks!

@jczic
Copy link
Owner

jczic commented Apr 1, 2020

Hello @gpspelle,

Could you use MicroWebSrv2 lib instead of MicroWebSrv 👍
(https://github.com/jczic/MicroWebSrv2)

You can check the OnWSChatTextMsg() function in main.py who is used to send msg to all WebSockets connections (for the chat example) registered in _chatWebSockets list.
You can first register websockets object (connections) in an array and after, send messages when you want (by a timer or any event).
It's ok for you?

@gpspelle
Copy link
Author

gpspelle commented Apr 1, 2020

Yeah, I'll try to use it, but I don't know if this will solve my problem in the end.

@jczic
Copy link
Owner

jczic commented Apr 2, 2020

And what's your problem exactly?

@Kiri-fr
Copy link

Kiri-fr commented Jun 12, 2020

Hi Gabriel, I had the same issue.
What you could do is:

def _acceptWebSocketCallback(webSocket, httpClient) :
print("WS ACCEPT")
global WS
WS = webSocket # Save socket access point for external use
webSocket.RecvTextCallback = _recvTextCallback
webSocket.RecvBinaryCallback = _recvBinaryCallback
webSocket.ClosedCallback = _closedCallback

WS.SendText("Hi")

This code was proposed by Marc Fiot

@gpspelle gpspelle closed this as completed Jul 4, 2021
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

3 participants