简体   繁体   中英

Connect to VM using Websocket

This could also been treated as a JS question even I'm using a lot of VMware terms.

I'm using Websocket to connect to a VM that is hosted by vSphere and is managed by vCloud Director.

By vCloud Director API, I can have the security ticket, which is something similar to cst-xlIs3pP+C/oL/tEgwqvBHv6cBFnTT//VfLNh2kwOjOJItTwfEmVmePhjmJHfV0CisjxqaiQ9AJCNwvfu1zpr1dptvANS9NoIk4TCto7gRsM79R633SS2cIEuvXUAs7KzPoqdjYnSM8BcCttHLz8UbaPPYhjxx1MS2sCfUYovjqtGa9QwkZVBPxrfuPHsJNn3XchTO2h1pm/c/kim2kyu3R3worzcTSZsjGIk+QMWdvfEXc/PNYUGASA0EmP/16IMCltnODY9gQ9ddV0LfXeNKw==-IB8jmkQf1OtvVXZsqoO/cT0Ou93Dx7JlMOTGdQ==--tp-49:4A:E1:31:6B:95:39:AD:47:6D:63:F6:1E:72:F7:D1:B5:65:36:00-- .

So, Websocket url is pretty much like this "wss://10.160.122.169/902;cst-xlIs3pP+C/oL/tEgwqvBHv6cBFnTT//VfLNh2kwOjOJItTwfEmVmePhjmJHfV0CisjxqaiQ9AJCNwvfu1zpr1dptvANS9NoIk4TCto7gRsM79R633SS2cIEuvXUAs7KzPoqdjYnSM8BcCttHLz8UbaPPYhjxx1MS2sCfUYovjqtGa9QwkZVBPxrfuPHsJNn3XchTO2h1pm/c/kim2kyu3R3worzcTSZsjGIk+QMWdvfEXc/PNYUGASA0EmP/16IMCltnODY9gQ9ddV0LfXeNKw==-IB8jmkQf1OtvVXZsqoO/cT0Ou93Dx7JlMOTGdQ==--tp-49:4A:E1:31:6B:95:39:AD:47:6D:63:F6:1E:72:F7:D1:B5:65:36:00--" in which 902 is the port returned by vCloud Director.

After I created this Websocket, my onopen function is invoked, does this mean the connection is established? However, after one or two seconds, the websocket onclose is invoked. Is this saying the server is closing the connection? The event code is 1006...

How can I debug more on this problem?

Close code 1006 means that the socket was just 'dropped' (a TCP disconnect) without a web socket protocol close frame being received ( https://tools.ietf.org/html/rfc6455 section 7.1.5)

There's any number of reasons why this could occur - it could be things like spotty network infrastructure or even flaky implementations of parts of the web socket protocol layers.

However since you're using an SSL connection another possibility is a disagreement on the certificates in use. Perhaps if the server side certificate is self-signed and you've not installed it in the browser initiating the connection (or it uses some sort internal CA and that CA is not recognized). Unfortunately most browsers don't give much information when they encounter poor certificates with web socket - there's no 'do you want to trust this cert' alert (unlike https).

You should also check to see if the ticket you have needs to be URL encoded - it's possible that the '=' characters in that string need to be replaced with %3d (url encoded). Though I honestly don't recall if the server side web socket handler requires that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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