<script type="text/javascript">
var ws = new WebSocket("ws://38.55.97.143:6162/");   # var ws = new Websocket(wss://pp111.yoongle.com/wss);

ws.onopen = function(event) {
console.log("WebSocket connection opened");
// 可以在这里发送数据给服务器
ws.send("Hello, server!");
};

ws.onmessage = function(event) {
console.log("Received message from server: " + event.data);
};

ws.onclose = function(event) {
console.log("WebSocket connection closed");
};

ws.onerror = function(error) {
console.error("WebSocket error observed:", error);
};
</script>
socket后台nginx配置
location /wss {  # WebSocket请求的路径
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://127.0.0.1:6162;  # WebSocket服务的地址和端口
  }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部