gpt4 book ai didi

php - WebSocket 连接到 'ws://localhost:8080/' 失败:连接建立错误:net::ERR_CONNECTION_REFUSED

转载 作者:行者123 更新时间:2023-12-04 16:13:10 26 4
gpt4 key购买 nike

我在客户端脚本和服务器之间没有 Websocket 连接。

它在我的本地环境中运行良好。

我也在关注这个 link .

这是一个服务器脚本,它初始化 websocket 服务器并监听到 8080 的客户端连接。港口。

public function run()
{
$loop = Factory::create();
$pusher = new Pusher;
$context = new Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onBlogEntry'));

// Set up our WebSocket server for clients wanting real-time updates
$webSock = new Server('0.0.0.0:8080', $loop); // Binding to 0.0.0.0 means remotes can connect
$webServer = new IoServer(
new HttpServer(
new WsServer(
new WampServer(
$pusher
)
)
),
$webSock
);

$loop->run();

这是客户端脚本:
var conn = new ab.Session('ws://localhost:8080',
function() {
/* subscribe to following topics */
conn.subscribe('new_order', function(topic, data) ..

同样,这在本地设置中运行良好。

另请注意,我的应用程序是使用 docker 容器中的指定端口托管的。
http://192.168.12.52:8094/xyz/new/....

我还尝试在客户端脚本中指定 IP:
var conn = new ab.Session('ws://192.168.12.52:8080',
function() {
/* subscribe to following topics */
conn.subscribe('new_order', function(topic, data) ...

在这种情况下,我收到以下错误:
WebSocket connection to 'ws://192.168.11.32:8080/' failed: Error during WebSocket handshake: Unexpected response code: 403

这里缺少什么?

最佳答案

这可能是 ssl 证书问题。我认为新的浏览器版本在没有 ssl 的情况下存在网络套接字问题。您可能有自签名证书。试试 https://192.168.12.52:8080如果您看到无效的证书错误(例如:您的连接不安全或您的连接不是私有(private)的),请单击前进或添加异常(exception),然后使用相同的浏览器重试。您也可以使用 wss://代替 ws://。

关于php - WebSocket 连接到 'ws://localhost:8080/' 失败:连接建立错误:net::ERR_CONNECTION_REFUSED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53374151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com