如何解决与对方的连接以不整洁的方式丢失
我一直在尝试使用Autobahn(JavaScript)和Crossbar制作基于WAMP RPC的简单应用程序,但它给了我以下错误:-
横杠跟踪:-
[Router 32589 crossbar.router.protocol.WampWebSocketServerProtocol] connection accepted from peer tcp4:[ip_address]:7110
[Router 32589 crossbar.router.protocol.WampWebSocketServerProtocol] Connection made to tcp4:[ip_address]:7110
[Router 32589 crossbar.router.protocol.WampWebSocketServerProtocol] dropping connection to peer tcp4:[ip_address]:7110 with abort=True: WebSocket opening handshake timeout (peer did not finish the opening handshake in time)
[Router 32589 crossbar.router.protocol.WampWebSocketServerProtocol] Connection to/from tcp4:[ip_address]:7110 was aborted locally
[Router 32589 crossbar.router.protocol.WampWebSocketServerProtocol] _connectionLost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionAborted'>: Connection was aborted locally using ITCPTransport.abortConnection.
JavaScript控制台日志:-
autobahn.min.js:90 using WAMP transport type: websocket
autobahn.min.js:181 WebSocket connection to 'ws://[domain]:8081/' Failed: Error in connection establishment: net::ERR_CONNECTION_RESET
autobahn.min.js:87 connection closed unreachable {reason: null,message: null,retry_delay: null,retry_count: null,will_retry: false}
main.js:43 Connection closed.
这是我正在运行的代码:-
横杠config.json
:-
{
"$schema": "https://raw.githubusercontent.com/crossbario/crossbar/master/crossbar.json","version": 2,"controller": {
},"workers": [
{
"type": "router","realms": [
{
"name": "name_1","roles": [
{
"name": "anonymous","permissions": [
{
"uri": "","match": "prefix","allow": {
"call": true,"register": true,"publish": true,"subscribe": true
},"disclose": {
"caller": false,"publisher": false
},"cache": false
}
]
}
]
}
],"transports": [
{
"type": "websocket","endpoint": {
"type": "tcp","port": 8081
},"url": "ws://[domain]","serializers": ["json"],"options": {
"allowed_origins": ["*"],"allow_null_origin": true,"enable_webstatus": false,"max_frame_size": 1048576,"max_message_size": 1048576,"auto_fragment_size": 65536,"fail_by_drop": true,"open_handshake_timeout": 2500,"close_handshake_timeout": 1000,"auto_ping_interval": 10000,"auto_ping_timeout": 5000,"auto_ping_size": 4,"compression": {
"deflate": {
"request_no_context_takeover": false,"request_max_window_bits": 13,"no_context_takeover": false,"max_window_bits": 13,"memory_level": 5
}
}
}
}
]
}
]
}
JavaScript:-
var connection=null;
AUTOBAHN_DEBUG = true;
require.config({
baseUrl: ".",paths: {
"autobahn":
"https://[domain]/path/to/autobahn.min.js","when": "https://cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when"
},shim: {
"autobahn": {
deps: ["when"]
}
}
});
require(["autobahn"],function(autobahn) {
console.log("Ok,Autobahn loaded",autobahn.version);
var connection = new autobahn.Connection({
transports: [{
type: 'websocket',port: '8081',host: '[domain]',url: "ws://[domain]:8081",}],realm: "name_1",max_retries: "0"
});
connection.onopen = function (session,details) {
// Publish,Subscribe,Call and Register
// session.register('com.myapp.add2',add2);
// session.call('com.myapp.add2',[2,3]).then(function showSum(res) {
// console.log('sum is',res);
// },session.log);
console.log("Connection opened.");
};
connection.onclose = function (reason,details) {
console.log("Connection closed.");
}
connection.open();
});
我已经尝试让这个简单的东西工作了一个多星期,却无法弄清缺少的东西。
在此先感谢您的帮助!
编辑:使用python(下面的代码)检查了相同的连接,效果非常好!但是我真的需要它在浏览器中工作。
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.application.internet import ClientService
from autobahn.wamp.types import ComponentConfig
from autobahn.twisted.wamp import ApplicationSession,WampWebSocketClientFactory
class MyAppSession(ApplicationSession):
def __init__(self,config):
ApplicationSession.__init__(self,config)
def onConnect(self):
self.join(self.config.realm)
def onChallenge(self,challenge):
pass
@inlineCallbacks
def onJoin(self,details):
yield self.call('update_price',price)
yield self.leave()
def onLeave(self,details):
self.disconnect()
def ondisconnect(self):
reactor.stop()
session = MyAppSession(ComponentConfig('name_1',{}))
transport = WampWebSocketClientFactory(session,url='ws://[domain]:8081')
endpoint = TCP4ClientEndpoint(reactor,'[domain]',8081)
service = ClientService(endpoint,transport)
service.startService()
reactor.run()
我测试了我最初在localhost上发布的相同JS代码,并且有效!因此,通过消除过程,我将其范围缩小到浏览器到服务器连接的一个问题(python可以连接到服务器,而js可以连接到本地主机)
此外,作为辅助解决方案,我只能在python中运行它,但是我已经在运行另一个连接,并且我需要它们彼此通信。我尝试使用多处理,但是由于某种原因它似乎不起作用(但是当我关闭另一个连接时它确实起作用),甚至都没有抛出任何错误,我尝试了try-except和pipe()。
任何一种设置的帮助(它们对我来说都可以达到相同的目标)将不胜感激。 :)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。