简体   繁体   English

Stilts.js无法通过安全true连接到Websocket服务器

[英]Stilts.js Unable to connect to websocket server with secure true

I am having issues with subscribing to my websocket server when I turn the secure option to true. 将安全选项设置为true时,我在预订Websocket服务器时遇到问题。 I ran an SSL validator to make sure it was set up properly and everything passed. 我运行了一个SSL验证程序,以确保它已正确设置并且一切都通过了。 Also to be safe, I also checked with my hosting provider so I dont believe that is the issue. 为了安全起见,我还与托管服务提供商进行了核对,所以我认为这不是问题。 And also, everything does work when secure is set to false. 而且,将安全性设置为false时,一切都会正常工作。

The WSS is running on port 8676, and I did make sure that port is open. WSS在端口8676上运行,并且我确保该端口已打开。

I am using the Stomp Javascript library. 我正在使用Stomp Javascript库。 I downloaded the latest version from their github master branch ( https://github.com/projectodd/stilts/blob/master/stomp-client-js/src/main/javascript/stomp.js ). 我从他们的github master分支( https://github.com/projectodd/stilts/blob/master/stomp-client-js/src/main/javascript/stomp.js )下载了最新版本。

I keep getting this error inside the _transmit() function: can't call transmit on undefined 我不断在_transmit()函数中收到此错误: can't call transmit on undefined

It seems to not be setting the _transport property inside of _buildConnector() function. 似乎未在_buildConnector()函数内部设置_transport属性。 I added some console.logs and it always goes to the else statement in this function. 我添加了一些console.logs,它总是转到此函数中的else语句。

Any ideas on a fix? 有任何解决办法吗? Or am I just missing something? 还是我只是想念一些东西?

This is how I am initializing my connection: 这是初始化连接的方式:

client = new Stomp.Client('my.ip.address', 8676, true);

Here is where I am logging some of the functions: 这是我记录某些功能的地方:

Stomp.Client = function(host, port, secure) { console.log('host param: ' + host); console.log('port param: ' + port); console.log('secure param: ' + secure); this._host = host || Stomp.DEFAULT_HOST; this._port = port || Stomp.DEFAULT_PORT || 8675; this._secure = secure || Stomp.DEFAULT_SECURE_FLAG || false; console.log('this._host: ' + this._host); console.log('this._port: ' + this._port); console.log('this._secure: ' + this._secure); }

Output: 输出:

host param: my.ip.address port param: 8676 secure param: true this._host: my.ip.address this._port: 8676 this._secure: true

_buildConnector: function(transports, i) { console.log('INSIDE _buildConnector()'); var callback = this._connectCallback; var client = this; if ( i < transports.length ) { console.log('IF!!!'); return function() { var fallback = client._buildConnector( transports, i+1, callback ); try { console.log('_buildConnector::IF::TRY'); transports[i].connect( function() { client._transport = transports[i]; callback(); }, fallback ); } catch (err) { console.log('_buildConnector::IF::CATCH'); fallback(); } }; } else { console.log('_buildConnector::ELSE'); return client.connectionFailed.bind(this); } }

Output: 输出:

INSIDE _buildConnector() IF!!! INSIDE _buildConnector() IF!!! _buildConnector::IF::TRY INSIDE _buildConnector() _buildConnector::ELSE _buildConnector::IF::TRY

connectionFailed: function() { console.log('INSIDE connectionFailed()'); if (this._errorCallback) { console.log('connectionFailed::IF'); console.log('this._errorCallback'); console.log(this._errorCallback); console.log('arguments'); console.log(arguments); this._errorCallback.apply(this._errorCallback, arguments); } else { console.log('connectionFailed::ELSE'); console.log('unable to connect :('); Stomp.logger.log( "unable to connect" ); } }

Output: No output.. 输出: No output..

I discovered this node.js tool called wscat which can be used to send messages to a websocket server ( http://einaros.github.io/ws/ ). 我发现了这个名为wscat node.js工具,该工具可用于将消息发送到websocket服务器( http://einaros.github.io/ws/ )。

When entering the command using the external address: wscat -c wss://my.ip.address:8676 使用外部地址输入命令时: wscat -c wss://my.ip.address:8676

I kept getting the following error: error: Error: Hostname/IP doesn't match certificate's altnames 我不断收到以下错误: error: Error: Hostname/IP doesn't match certificate's altnames

But when I changed it to my domain name: wscat -c wss://mydomain.com:8676 但是,当我将其更改为我的域名时: wscat -c wss://mydomain.com:8676

I was given this message: connected (press CTRL+C to quit) 我收到此消息: connected (press CTRL+C to quit)

Which led me to: 这导致我:

I am setting the host value in Javascript as the external ip address of the server where STOMP lives. 我将Javascript中的主机值设置为STOMP所在服务器的外部ip地址。 But the SSL cert is configured for a domain name. 但是SSL证书是为域名配置的。 This led me to think that I should use mydomain.com instead of my.ip.address for the host parameter in new Stomp.Client . 这导致我认为我应该使用mydomain.com而不是my.ip.address作为new Stomp.Client的host参数。 But this is resulting in the following error in the Torquebox log file: 但这会在Torquebox日志文件中导致以下错误:

NoSuchHostException: No such host: mydomain.com

So then in the torquebox.yml file the host property needed to be configured to mydomain.com as well. 因此,然后在torquebox.yml文件中,也需要将主机属性配置为mydomain.com

So the conclusion is: You need to use the domain name that was registered to the SSL cert when trying to connect to your websocket server, not the external ip address. 因此结论是:尝试连接到Websocket服务器时,需要使用注册到SSL证书的域名,而不是外部IP地址。 huzzah! 头晕!

Credit to: @bobmcwhirter who helped lead me to this solution here: https://github.com/projectodd/stilts/issues/20 归功于:@bobmcwhirter,他帮助将我引导到此解决方案: https : //github.com/projectodd/stilts/issues/20

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM