Git Product home page Git Product logo

Comments (3)

morozovsk avatar morozovsk commented on August 19, 2024 1

конечно можно, например в примере chat2 при получении сообщения с локального сокета в обработчике onServiceMessage($connectionId, $packet) для отправки ответа в это же соединение назад используется $this->sendToService($connectionId, $packet);
А считывать ответ в своём скрипте лучше не с помощью fread($instance, 4096), а fgets($instance)
https://github.com/morozovsk/websocket-examples/blob/master/chat2/server/Chat2WebsocketMasterHandler.php

from websocket.

morozovsk avatar morozovsk commented on August 19, 2024

соединяться надо не с вебсокетом, а локальным сокетом.
ваше условие надо вставлять не в onOpen, а в onServiceMessage.

from websocket.

borodatych avatar borodatych commented on August 19, 2024

Хм.. Явно не понимание с моей стороны...

Я ваш Send переделал в свой New, который работает через Web и простым GET запросом вызывается:

<?php

$userId = @$_GET['s'];
$message = @$_GET['a'];

if( $userId && $message )
{
    if( 'readNewMsg'==$message )
    {
        $localsocket = 'tcp://127.0.0.1:8010';
        $instance = stream_socket_client ($localsocket, $errno, $errstr);
        fwrite($instance, json_encode( ['message' => $message, 'userId' => $userId] )."\n");
    }
    else die("access denied ....");
}
else die("access denied ...");

И все работало, кроме как, не обратил внимание, хотел вернуть ответ "ok" при удачной отправке.
Но "ok" писалось в консоль.
Сейчас удалось получить пинг по пользователю, но так же в консоль.

Создать новый тикет или ответите здесь?
Можно как то через GET или POST запрос файлу отдать ответ, не в консоль имею ввиду?

Попробовал только-что так:

<?php
$userId = @$_GET['s'];
$message = @$_GET['a'];

if( $userId && $message )
{
    $output = shell_exec(__DIR__."/Send.php $userId $message");
    echo "<pre>$output</pre>";
}
else die("access denied");

Все равно в консоль пишет...

from websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.