简体   繁体   中英

Expose socket via web sockets

I have a server that creates a socket on port 8181. I would like to access that socket from a web page opened in Google Chrome 14. I suppose it is not possible in a straight manner. Chrome provides support for Web Sockets but not for standard sockets. Is that right?

Is is possible to somehow create an intermediary that would expose my socket server listening on port 8181 as a web socket server running on some other port?

websockify is a generic WebSockets to TCP socket proxy/bridge. I created websockify originally to allow noVNC (HTML5 VNC client) to be able to connect to an unpatched VNC server. But it is generically useful (not VNC specific) so I spun it off as a separate project.

On a UNIX/Linux system you would run websockify like this:

./websockify 8080 my_server:8181

Port 8080 in the above example is the port to listen for WebSocket connections. my_server is the name/IP of your system where you have a server listening on port 8181. If you are running websockify on the same system as your server then you can just use localhost in place of 'my_server'.

The websockify project also comes with a Javascript wrapper library called websock.js. websockify supports the new protocol versions (used by Chrome 14+ and Firefox 6+) but it also works with older versions. However, with the older versions of the protocol there is no way to send raw binary data (only UTF-8), so websock.js and websockify work together to base64 encode/decode the data (between the browser and websockify) when using the older protocol so that you can still send raw binary data to/from the target.

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