在本地运行web-Socket进行调试 [英] Run web-Socket locally for debug

查看:3103
本文介绍了在本地运行web-Socket进行调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用大猩猩网络套接字,我想在本地运行它,我的意思是使用下面的chrome客户端
或其他推荐的工具...当我进入调试模式时,我得到了错误



我使用

 github.com/gorilla/websocket


var upgrade = websocket.Upgrader {
ReadBufferSize:1024,
WriteBufferSize:1024,
}

upgrader.CheckOrigin = func(r * http .Request)bool {return true}
$ bc,err:= upgrader.Upgrade(w,r,nil)
if err!= nil {
log.Print(upgrade :,err)
return
}

当我运行以下url在Chrome或Web套接字客户端中,我收到了错误

websocket:不是websocket握手:在'Connection'标题中找不到'upgrade'标记

  localhost:8081 / mypath 

我想运行它
$ b $ pre $ $ $ $ c $ ws:// localhost:8081 / mypath

并为本地模拟提供标记,我该怎么做呢?

要检查它,我使用简单的WebSocket客户端。任何其他客户都会有所帮助

编辑:



chrome控制台我得到了以下错误:


VM42:164拒绝连接到'ws:// localhost:8081 / mypath',因为它
违反了以下内容安全策略指令:connect-src
'self'uploads.github.com status.github.com collector.githubapp.com
api.github.com www。 google-analytics.com github-cloud.s3.amazonaws.com
github-production-repository-file-5c1aeb.s3.amazonaws.com
github-production-upload-manifest-file-7fdce7.s3 .amazonaws.com
github-production-user-asset-6210df.s3.amazonaws.com
wss://live.github.com



解决方案

浏览器在获取Web页面时不使用WebSocket协议来显示,从浏览器使用WebSocket端点需要代码。



Gorilla包包含示例,显示如何从浏览器进行连接( chat and
websocket / blob / b89020ee79b89a7f932c5617d218fc06db382f53 / examples / command / home.html#L31-L45rel =nofollow noreferrer>命令
示例是很好的开始)

您可以使用浏览器控制台连接到WebSocket端点:

 > ws = new WebSocket(ws:// localhost:8080 / mypath)
> ws.onmessage = function(ev){console.log(ev.data)}
> ws.send(hello)


I’m using gorilla web socket and I want to run it locally , I mean with the following chrome client or other recommended tool …when I run into debug mode I got error

I use

"github.com/gorilla/websocket"


var upgrader = websocket.Upgrader{
    ReadBufferSize:  1024,
    WriteBufferSize: 1024,
}

upgrader.CheckOrigin = func(r *http.Request) bool { return true }

c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
    log.Print("upgrade:", err)
    return
}

When I run the following url in chrome or web socket client I got error

websocket: not a websocket handshake: 'upgrade' token not found in 'Connection' header

localhost:8081/mypath

and I want to run it

ws://localhost:8081/mypath

and provide token for local simulation, how I can do it ?

To check it I use Simple WebSocket Client of chrome. any other client will be helpful

EDIT:

when I try it in the chrome console I got the following error:

VM42:164 Refused to connect to 'ws://localhost:8081/mypath' because it violates the following Content Security Policy directive: "connect-src 'self' uploads.github.com status.github.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss://live.github.com

解决方案

Browsers do not use the WebSocket protocol when fetching a web page for display. Code is required to use a WebSocket endpoint from a browser.

The Gorilla package includes examples showing how to connect from a browser (the chat and command examples are good places to start).

You can can connect to a WebSocket endpoint using the browser console:

> ws = new WebSocket("ws://localhost:8080/mypath")
> ws.onmessage = function(ev) { console.log(ev.data) }
> ws.send("hello")

这篇关于在本地运行web-Socket进行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆