I am trying to implement push integration using php and native zmq. I successfully sent my message to the server, but the problem is that I cannot send the message to the browser using js Websocket (). I say that the connection to WebSocket with "ws: //127.0.0.1: 8080 /" failed: WebSocket handshake error: invalid status bar
here is my code for the client:
<?php try { function send($data) { $context = new ZMQContext(); $push = new ZMQSocket($context, ZMQ::SOCKET_PUSH); $push->connect("tcp://localhost:5555"); $push->send($data); } if(isset($_POST["username"])) { $envelope = array( "from" => "client", "to" => "owner", "msg" => $_POST["username"] ); send(json_encode($envelope));
client
here is my server:
$context = new ZMQContext(); $pull = new ZMQSocket($context, ZMQ::SOCKET_PULL); $pull->bind("tcp://*:5555");
and here is my owner.php, I expect the data to be sent via Websocket in the browser:
<html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h2>Message</h2> <ul id="messagelog"> </ul> <script> var logger = document.getElementById("messagelog"); var conn = new WebSocket("ws://127.0.0.1:8080"); # the error is pointing here. conn.onOpen = function(e) { console.log("connection established"); } conn.onMessage = function(data) { console.log("recieved: ", data); } conn.onError = function(e) { console.log("connection error:", e); } conn.onClose = function(e) { console.log("connection closed~"); } </script> </body>
Please tell me what I am missing. thanks.
javascript php pushstate websocket zeromq
loki9
source share