-
Notifications
You must be signed in to change notification settings - Fork 75
Sending messages from server to clients #69
Comments
Hello :-), So let's start by question 2 (the first one, because you have two 2 😉). Each connection is represented by a node. Maybe this Section of the documentation might help you, http://hoa-project.net/En/Literature/Hack/Websocket.html#Customized_node. Next, question 1. PHP is synchronous by nature. You cannot listen to incoming message while having another execution where you send messages. This is possible if you use pthread for instance or some tricks to get a pseudo-asynchronous execution with generators and co-routines. Finally, question 3. Answered with the previous paragraph. |
1) I think you may have misunderstood me, will try to explaine.
2) Yes, I think it will be help, need to try, thanks. 3) I understand, but how you can solved this problem, if you need answer each client every minute? |
So you want that:
Is it correct? |
Yes and yes. I think, I can extend the loop circul, and call once in 3 seckonds my method that sending data to clients. Whay You think abut this? |
You cannot have 2 infinite loops inside the same thread. When calling the famous I recommend 2 solutions: Using pthread, or using generators/co-routines libraries to simulate asynchronous execution. Most people uses pthread for this usages. Or, you can use 2 servers. |
Did you have your answer or should we keep this issue open? |
Can we create something like this: https://github.com/Shkarbatov/WebSocketPHPWorkerman/blob/master/worker.php ? |
This is almost the actual API of What do you mean? |
Can I send data from server to client with Hoa like I do this with workerman? |
Hello @Shkarbatov, Yes, as long you save the client (fro source bucket) during client established connection to the server. |
Thanks for answer, do you have any example? |
Trying next: Worker:
Web Client:
PHP Client:
Web client connected to worker and save his backet, then I run php client and worker receive message, find backet needed web client and send message, but it not send and I don't have any errors. Any idea what it can be? |
Any idea, why it is not working? |
Well, problem next: I saved bucket next:
And then, when I want to send:
if I will not put Socket\Node as the second parametr of the send function it will used current node:
This is ok, but if I will used Node from saved backed:
It will return current node, not saved node. So I need to save separate bucket and node:
And when send message add saved node:
Is this bug? Can I somehow receive node from saved bucked? |
Hi, I have some problems, unfortunately I can't find this in documentation, so hope you will help me.
I have own API, that receive message and this message I need to show.
Incoming message from API, I saved in DB on one day.
Message can be for everyone users, for some group or just for one.
I send user data from javascript to the socket once, when a page is rendered.
On server side I need to add my business logic.
I trying like this:
But while (true) {} will blocking SocketServer, and it will be works only for first client.
And trying like this:
But it not works too =(
Questions:
1) How I can send message from server to client, not only when client send message?
2) How I can identify user as node, to filter it in future and how to filter it by user_id?
2) Where I need to adding while(true) {} ?
Thanks for any advice!
The text was updated successfully, but these errors were encountered: