如何从用Go编写的客户端连接到sockJS?

我有一个使用websocket的服务器。 它用Go语言编写。 为了进行测试,我还有一个用Go编写的应用程序。 要进行测试,我启动服务器,然后运行测试客户端。 测试客户端创建到服务器的Websocket连接并执行操作(基本上模拟用户活动)。 客户端和服务器都使用gorilla / websockets库,标准浏览器也可以在服务器上正常工作。</ p>

一切正常。</ p>

< p>为支持不兼容的浏览器,要求我开始使用 SockJS Go服务器 图书馆。 我做到了,当客户端使用 SockJS 库从浏览器使用新版本时,新版本就可以很好地工作。</ p>

现在解决该问题。 SockJS不接受输入的Websocket连接。 仅来自SockJS客户端的连接。 因此我的测试应用程序无法正常工作,并且无法进行测试。</ p>

我可以从git中恢复旧版本的连接代码,并使用gorilla /创建单独的连接类型 websockets,让我的服务器在仅侦听localhost的其他端口上侦听。 这将允许我测试功能。 缺点是我必须维护两个基本相同代码的版本,并且我不会测试实际的用户体验,并且可能直到生产后才发现错误。</ p>

理想情况下,SockJS服务器 ,考虑到它仍然使用</ em>大猩猩/ websockets作为依赖项将自动接受正确的websocket连接,但除非我似乎需要在SockJS客户端库中提供,但据我所知,确实没有 不存在。</ p>

有人对此有解决方案吗? 谢谢!</ p>
</ div>

展开原文

原文

I have a server that uses websockets. It is written in Go. For testing, I have another application written in Go. To test, I start the server, then run the test client. The test client creates websocket connections to the server and does things (basically impersonating user activity). Both the client and the server are using the gorilla/websockets library, and standard browsers also work fine with the server.

This was all working beautifully.

To support non-compliant browsers, I was asked to start using the SockJS Go server library. I did this and the new version works just fine when used from a browser by clients using the SockJS library.

Now for the problem. SockJS does not accept incoming websocket connections. Only connections from the SockJS client. So my testing application doesn't work, and I'm unable to test.

I could recover the old version of my connection code from git and make a separate connection type that uses gorilla/websockets and have my server listen on an additional port that only listens on localhost. This would allow me to test the functionality. The downside is that I have to maintain two versions of essentially the same code, and I wouldn't be testing the real user experience and possibly not find bugs until production.

Ideally the SockJS server, considering it still uses gorilla/websockets as a dependency would automatically accept proper websocket connections, but barring that it seems I'd need a SockJS client library in Go which, as far as I can tell, doesn't exist.

Does anyone have a solution for this? Thanks!

douce1368
douce1368 Yandry:我不知道。我认为支持我们所要支持的只是一个后备。这是一个非常受欢迎的公共站点,因此我们可能会在所有台式机和移动操作系统上获得尽可能多的浏览器。
3 年多之前 回复
dqh19413
dqh19413 “支持不兼容的浏览器”是哪一个?
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问