0

I have created a websocket with Ratchet PHP websocket library.In case of my localhost the server is not stopping but in case of my current server the socket is being stopped after few minutes.

I have tried with many ports and different libraries, in all the cases the connection is stopped after few minutes.

What I am trying to do is to connect a desktop app with my server via a websocket I wanna send some data to print in some condition. But the connection is being stopped that's my problem . If anybody can please help me or suggest me ,thanks a lot in advance.

Here is my ratchet code:

<?php 
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;

    require dirname(__DIR__) . '/vendor/autoload.php';

    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                new Chat()
            )
        ),
        9301
    );

    $server->run();

I am using another library to send data to clients:

use WebSocket\Client;
$client = new Client("ws://www.mydomain.com:9301");
$client->send('Testing new msg');

I am testing in client side with this JS script :

var conn = new WebSocket('ws://www.mydomain.com:9301');
conn.onopen = function(e) {
    console.log("Connection established!");
};

conn.onmessage = function(e) {
    console.log(e.data);
};

But after few minutes the connection getting stopped.

Ishaque Javed
  • 406
  • 4
  • 14

0 Answers0