服务器上开启一个websocket,本地测试连接,报错

守护

报错内容:
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>
阅读 5378
4个回答

静默

连错端口了,17000和70000是有区别的 - -!

  • 暂无评论
守护

可以连接上了,非常感谢!

  • 暂无评论
zhanghuan

兄弟怎么解决的

  • 暂无评论
tomlibao

客户端和服务端 端口不一致

  • 暂无评论