简体   繁体   English

网络套接字 | net::ERR_CONNECTION_REFUSED

[英]WebSocket | net::ERR_CONNECTION_REFUSED

I've tried to build up a WebSocket connection between我试图建立一个 WebSocket 连接之间
a PHP Websocket server and JavaScript.一个 PHP Websocket 服务器和 JavaScript。 It looks like看起来像
the server is running, but I can't build up a connection.服务器正在运行,但我无法建立连接。
Every time I've tried to build up a connection I've got an每次我尝试建立联系时,我都会得到一个
error, wich say's:错误,说的是:

WebSocket connection to 'ws://xxx.xxx.xxx.xx:1414/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

Is anyone here who knows the solution for this problem?这里有人知道这个问题的解决方案吗?
By the way, I'm using XAMPP, on a Windows device, to host顺便说一句,我在 Windows 设备上使用 XAMPP 来托管
the PHP server, which is running on port 80 PHP 服务器,在端口80运行

PHP server: PHP服务器:

<?php
// Error Reporting und Zeitlimit für Serverbetrieb setzen
error_reporting(E_ERROR);
set_time_limit (0);

$host = 'localhost'; // Serverhost auf der gelauscht werden soll
$port = 1414; // Port auf dem Verbindungen angenommen werden sollen

// Socket erstellen
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

// Socket an Adresse und Port binden
socket_bind($sock, $host, $port);

// An Port lauschen
socket_listen($sock);

$sockets = array($sock);
$arClients = array();

while (true)
{

echo "Warte auf Verbindung...rn";

$sockets_change = $sockets;
$ready = socket_select($sockets_change, $write = null, $expect = null, null);

echo "Verbindung angenommen.rn";

foreach($sockets_change as $s)
{
if ($s == $sock)
{
// Änderung am Serversocket
$client = socket_accept($sock);
array_push($sockets, $client);
print_r($sockets);
}
else
{
// Eingehende Nachrichten der Clientsockets
$bytes = @socket_recv($s, $buffer, 2048, 0);
}
}
}
 ?>

JavaScript code: JavaScript 代码:

  webSocket = new WebSocket('ws://xxx.xxx.xxx.xx:1414');
  webSocket.send("Here's some text that the server is urgently awaiting!");

The solution was quite simple.解决办法很简单。
I've just changed the port to 80我刚刚将端口更改为 80

Now it's should look like this:现在它应该是这样的:

ws://xxx.xxx.xxx.xx:80 ws://xxx.xxx.xxx.xx:80

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Heroku上的WebSocket ERR_CONNECTION_REFUSED - WebSocket on Heroku ERR_CONNECTION_REFUSED Websocket连接被拒绝。 WebSocket与&#39;ws://127.0.0.1:2000 /&#39;的连接失败:连接建立错误:net :: ERR_CONNECTION_REFUSED - Websocket connection refused. WebSocket connection to 'ws://127.0.0.1:2000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED WebSocket 连接到“wss://ip:8080/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED - WebSocket connection to 'wss://ip:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED WebSocket 连接失败:连接建立时出错:.net::ERR_CONNECTION_REFUSED - WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED chrome 扩展 WebSocket 连接到“ws://localhost:9090/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED - chrome extension WebSocket connection to 'ws://localhost:9090/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED JQuery 网络::ERR_CONNECTION_REFUSED - JQuery net::ERR_CONNECTION_REFUSED 端口8888 net :: ERR_CONNECTION_REFUSED - port 8888 net::ERR_CONNECTION_REFUSED net::ERR_CONNECTION_REFUSED 使用 websockets - net::ERR_CONNECTION_REFUSED using websockets 错误选项 net::ERR_CONNECTION_REFUSED - Error OPTIONS net::ERR_CONNECTION_REFUSED 科尔多瓦应用程序上的 net::ERR_CONNECTION_REFUSED - net::ERR_CONNECTION_REFUSED on cordova app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM