报错内容:
WebSocket connection to 'ws://58.247.98.146:17000/' failed: Error during WebSocket handshake: net::ERR_INVALID_HTTP_RESPONSE
服务器workerman开启websocket:
use Workerman\Worker;
use Workerman\Lib\Timer;
use Workerman\connection\AsyncUdpConnection;
require_once 'Workerman-master/Autoloader.php';
require_once 'Workerman-master/mysql_master/src/Connection.php';
require_once 'common.php';
$worker = new Worker("websocket://0.0.0.0:70000");
$worker->name = "worker";
$worker->onWorkerStart = function ($worker) {
};
//当收到用户发送的信息时
$worker->onMessage = function ($connection, $data) use ($worker) {
$connection->send($data);
};
html/js:
<script>
var ws = new WebSocket('ws://58.247.98.146:17000');
ws.onopen = function(){
var uid = 'uid1';
ws.send(uid);
};
ws.onmessage = function(e){
alert(e.data);
};
</script>
连错端口了,17000和70000是有区别的 - -!
可以连接上了,非常感谢!
兄弟怎么解决的
客户端和服务端 端口不一致