Closed ananchevegor closed 11 months ago
Please try let ws = new WebSocket("wss://yourdomain:2346");
Please try
let ws = new WebSocket("wss://yourdomain:2346");
i tried it anyway i have this error even when wtire domain
Please type https://yourdomain:port
directly into your browser's address bar.
If your service is running correctly, then information about the WebSocket and Workerman versions will be displayed.
Also, if you plan to create HTTPS or WSS services, it is recommended to use nginx/apache to proxy SSL.
ws.php:
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$context = [
'ssl' => [
'local_cert' => __DIR__ .'/ssl/server.pem',
'local_pk' => __DIR__ .'/ssl/server.key',
'verify_peer' => false,
]
];
$worker = new Worker('websocket://0.0.0.0:8282', $context);
$worker->transport = 'ssl';
$worker->onMessage = function(TcpConnection $con, $msg) {
$con->send('ok');
};
Worker::runAll();
js code:
ws = new WebSocket("wss://mydomain.com:8282");
ws.onopen = function() {
alert("连接成功");
ws.send('tom');
alert("给服务端发送一个字符串:tom");
};
ws.onmessage = function(e) {
alert("收到服务端的消息:" + e.data);
};
Thanks all works
Hey, i have this problem. I have website on real server, i have domain and ip adress. i have this code on server side and when i start it, the server write start success
this is code from server.php
i should use wss because site has https protocol. and when i write scripts in html i used
let ws = new WebSocket("wss://ip_real_server:2346");
and become this error
everywhere when wrote ip_real_server its ip my real server.
so, and question, what i need to use instead of
let ws = new WebSocket("wss://ip_real_server:2346");
should i use website's domain? or something else?