I want to subscribe the Spring framework WebSocket and receive the reply.
According to my target WebSocket server, the communication is done using STOMP publish protocol (Build based on Java Springframework API) https://stomp.github.io/stomp-specification-1.1.html
Now the client that I am working on, is build based on PHP and using https://github.com/Textalk/websocket-php/ for websocket client.
My idea to receive the server response is to follow the STOMP over Websocket technique based on this guy's answer Websocket Client not receiving any messages.
Using the current websocket client, I perform these steps
Send Connection (request?)
Send Subscription
Actively receive the reply
$client = new WebSocket\Client($ws_url); //Step 1 Inintate connection; $open_msg = "CONNECT\naccept-version:1.0,1.1,2.0\n\n\x00\n"; //Step 2 Subscribe Request; $client->send($open_msg); $subs = "SUBSCRIBE\nid:0\ndestination:/user/queue\nack:auto\n\n\x00\n"; $client->send($subs); while (true) { try { $message = $client->receive(); echo $message; // Act[enter image description here][4] on received message // Later, Break while loop to stop listening } catch (\WebSocket\ConnectionException $e) { // Possibly log errors } } $client->close();
The connection (Step 1) is done and tested.
current send and receive result image
Since it is running on the loop, the Received
is always printed.
Does anyone know why the API did not send reply?