Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
618 views
in Technique[技术] by (71.8m points)

ajax - How to establish a TCP Socket connection from a web browser (client side)?

I've read about WebSockets but they don't seem to be pure "sockets", because there is an application layer protocol over them. "ws:"

Is there any way of doing a pure socket connection from a web browser, to enliven webpages?

Here are my random stabs in the dark

  • Applets sockets provided by Java (need java installed)
  • Flash sockets provided by Flash (need flash installed)

But about HTML5, Why are they called WebSockets if they aren't Sockets?

Is the websocket protocol so simple to implement that it is "almost"-sockets?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've read about WebSockets but they don't seem to be pure "sockets", because there is an application layer protocol over them.

[Is the] websocket protocol so simple to implement that [it is] "almost"-sockets?

Allowing regular socket connections directly from the browser is never going to happen because it opens up a huge risk. WebSockets is about as close to raw sockets from the browser as you are going to get. The initial WebSockets handshake is similar to an HTTP handshake (allowing web servers to proxy/bridge it) and adds CORS type security. In addition, WebSockets is a message based transport (rather than streaming as raw TCP) and this is done using a two byte header on each message frame.

Even flash is not able to quite make raw TCP connections. Flash sockets also add CORS security, but instead of an in-band handshake, flash socket connections make a connection to port 843 on the target server to request a security policy file.

Is there any way of doing a pure socket connection from a web browser, to enliven webpages?

Yes, you can use my websockify bridge/proxy which allows a WebSockets enabled browser to connect directly to a TCP socket via websockify.

But about HTML5, Why are they called WebSockets if they aren't Sockets?

WebSockets are a transport built on TCP sockets. After the handshake there is very minimal overhead (typically just a two byte header).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...