An Issue while connecting WebSocket (socketo.me) to the hosted server
server.php
<?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()
)
),
8383
);
$server->run();
chatroom.php
<script type="text/javascript">
$(document).ready(function(){
var conn = new WebSocket('ws://localhost:8383');
conn.onopen = function(e) {
console.log("Connection established!");
};
...
</script>
As I tried to run the chat app from localhost connected to MySQL database which had been coded with PHP via WebSocket it was successful.
Also when I tried to run from the PuTTY terminal logged into SSH credentials, it was displaying as Server Started with the port# 8383
somelabz@bh-ht-3 [~/public_html/chatroom-php-mysql/bin]# php server.php
Server Started.somelabz@bh-ht-3 [~/public_html/chatroom-php-mysql/bin]# php server.php
Server Started.
The server starts with any of the port# except with 8080. So as I have decided to open the port with 8383, as a result, it had started successfully
With the port 8080, error_log was getting generated as
[07-Oct-2018 06:11:02 Etc/GMT] PHP Fatal error: Uncaught RuntimeException: Failed to listen on "tcp://0.0.0.0:8080": Address already in use in /home/somelabz/public_html/chatroom-php-mysql/vendor/react/socket/src/TcpServer.php:164
Stack trace:
#0 /home/somelabz/public_html/chatroom-php-mysql/vendor/react/socket/src/Server.php(36): React\Socket\TcpServer->__construct('tcp://0.0.0.0:8...', Object(React\EventLoop\StreamSelectLoop), Array)
#1 /home/somelabz/public_html/chatroom-php-mysql/vendor/cboden/ratchet/src/Ratchet/Server/IoServer.php(59): React\Socket\Server->__construct('0.0.0.0:8080', Object(React\EventLoop\StreamSelectLoop))
#2 /home/somelabz/public_html/chatroom-php-mysql/bin/server.php(15): Ratchet\Server\IoServer::factory(Object(Ratchet\Http\HttpServer), 8080)
#3 {main}
thrown in /home/somelabz/public_html/chatroom-php-mysql/vendor/react/socket/src/TcpServer.php on line 164
How am I suppose to resolve/overcome while connecting it from the WebSocket especially from the hosted server with the domain name such as http://somelabz.ml/chatroom-php-mysq
var conn = new WebSocket('ws://localhost:8383');
This was the composer files generated after executing and adding src folder $composer require cboden/ratchet
composer.json(On Server)
{
"autoload": {
"psr-4": {
"MyApp\\": "src"
}
},
"require": {
"cboden/ratchet": "^0.4.1"
}
}
composer.json(On localhost)
{
"autoload": {
"psr-4": {
"MyApp\\": "src"
}
},
"require": {
"cboden/ratchet": "^0.4.3"
}
}
Port 8080 is already being used by another service
@nishanth6 - I am closing this issue. Please let us know if you resolved your issue and how.
Failed to listen on "tcp://...*:8080": Cannot assign requested address @mbonneau