简体   繁体   English

连接到 websocket 服务器:从 javascript 正常,从 php 不正常

[英]Connection to websocket server : OK from javascript, not OK from php

I am using socketio to run a websocket server.我正在使用 socketio 运行 websocket 服务器。

var fs = require('fs');
var options = {
  key: fs.readFileSync('/etc/letsencrypt/live/my.domain.be/privkey.pem'),
  cert: fs.readFileSync('/etc/letsencrypt/live/my.domain.be/fullchain.pem')
};
var app = require('https').createServer(options)
  , io = require('socket.io').listen(app)

app.listen(6666);

Connecting to it from javascript (using socket.io client) works fine.从 javascript(使用 socket.io 客户端)连接到它工作正常。

var socket = io.connect('wss://my.domain.be:6666');

This works also :这也有效:

var socket = io.connect('https://my.domain.be:6666');

Now I want to connect using php.现在我想使用 php 连接。 I found a simple php client here : How can I send data/text from PHP using WebSocket to process?我在这里找到了一个简单的 php 客户端: How can I send data/text from PHP using WebSocket to process?

But I see no incoming connection when using :但是我在使用时看不到传入连接:

$WebSocketClient = new WebsocketClient('wss://my.domain.be', 6666);
$WebSocketClient->sendData("MyUserNameFromPHP");

And I get the error :我得到错误:

Error: 22145040:Unable to find the socket transport "wss" - did you forget to enable it when you configured PHP?错误:22145040:无法找到套接字传输“wss”——您是否在配置 PHP 时忘记启用它?

When using :使用时:

$WebSocketClient = new WebsocketClient('https://my.domain.be', 6666);

I get the error :我收到错误:

Error: 10905616:Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?错误:10905616:无法找到套接字传输“https” - 您是否在配置 PHP 时忘记启用它?

When using tls:// or ssl:// I get no output at all (and still no connection on my websocket server).使用 tls:// 或 ssl:// 时,我根本没有输出(并且在我的 websocket 服务器上仍然没有连接)。

So what am I missing to make a websocket connection from my php code ?那么从我的 php 代码建立 websocket 连接我错过了什么?

https://stackoverflow.com/a/61808878/3701985 please try my answer on another similar thread, I actually tried multiple solutions and now just want to provide answer which worked for me. https://stackoverflow.com/a/61808878/3701985请在另一个类似的线程上尝试我的回答,我实际上尝试了多种解决方案,现在只想提供对我有用的答案。 https://github.com/ratchetphp/Pawl https://github.com/ratchetphp/Pawl

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

相关问题 PHP Websocket服务器和JavaScript连接 - PHP websocket server and JavaScript connection 从php执行Java-从cmd确定,从php不执行(Windows) - Execute java from php - from cmd ok, from php not (windows) Keycloak无法从本地php服务器授权客户端,但在使用邮递员时返回ok - Keycloak fails to authorize client from local php server, but return ok when using postman 如何从PHP Server NOT Javascript连接到Websocket Server - How to connect to Websocket Server from PHP Server NOT Javascript Sphinx从linux控制台运行正常,但不是从php api运行 - Sphinx runs OK from linux console but not from php api 来自PHP的输出=正常,来自DOMPDF的输出=错误。 (显示) - output from PHP = ok, from DOMPDF = wrong. (display) Mongodb通过Laravel / PHP检查连接是否正常 - Mongodb check if connection is ok via Laravel/PHP 服务器说:当我从移动设备访问该站点时,在握手过程中未定义索引 Sec-WebSocket-Key。 从同一台电脑(本地主机)可以 - The server says: Undefined index Sec-WebSocket-Key during handshake process when I access the site from mobile. From the same pc (localhost) its ok 从PHP在线发布多部分表单(在localhost上一切正常) - posting multipart form from php online ( everything ok on localhost ) AJAX:在单独的调用中从同一PHP动态加载数据好吗? - AJAX: dynamically loading data from the same php in separate calls ok?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM