A
A
Anton Nikolaev2019-11-18 15:05:25
PHP
Anton Nikolaev, 2019-11-18 15:05:25

How to get rid of "POST net::ERR_CONNECTION_RESET" error?

I'm doing a php Ratchet chat and I'm having trouble with push notifications.

I'm sending a user message via ajax to send_message.php, and I'm getting an error: "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('Ошибка подключения к серверу ;)');
    },
    {'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:
<?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));

The error, as far as I understand, lies in this line:
$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher')

Please tell me how to solve my problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jack Williams, 2019-12-06
@AntonNikolaew

Set the following OpenServer settings. Should earn.
As far as I know, Apache is there by default, ZMQ is not friendly with it for a number of reasons, judging by your question, it makes no sense to list them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question