如何摆脱«POST net :: ERR_CONNECTION_RESET»错误?

时间:2019-11-19 22:03:08

标签: javascript php ajax push zeromq

我正在与php Ratchet聊天,我在使用push tutorial时遇到了困难

我正在将用户消息发送到send_message.php,但有一个错误:“ POST work-fox / send_message.php net :: ERR_CONNECTION_RESET”。

chat.js:

var panel = document.querySelector('.panel');
var message = document.querySelector('.message');
var start_dialog = document.querySelector('#start_dialog');
var send_msg = document.querySelector('#send_msg');
var chatId = '1';  

var conn = new ab.Session('ws://localhost:8443',
    function() {
    conn.subscribe(chatId, function(topic, data) {
            console.log(data);
        });
    },
    function() {
        console.warn('WebSocket connection closed');
    },
    {'skipSubprotocolCheck': true}
);

send_msg.onclick = function(e) {
    e.preventDefault(); 
    var xhr = new XMLHttpRequest();
    var form = new FormData();
    form.append('message', message.value); 
    xhr.open("POST", "send_message.php", true);
    xhr.send(form);
    xhr.onload = function(e) { 
        console.log(this.responseText);
    }
}

send_message.php:

$entryData = array(
    'fromId' => '1',
    'message' => $_POST['message'],
    'toId' => '2'
);

$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher');
$socket->connect("tcp://localhost:5555");
$socket->send(json_encode($entryData));

据我所知,该错误位于以下行:$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher') 请告诉我如何解决我的问题

0 个答案:

没有答案