Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 941
Hernán Eche Avatar asked Nov 08 '11 13:11

Hernán Eche


People also ask

How is a TCP connection established?

TCP uses a three-way handshake to establish a reliable connection. The connection is full duplex, and both sides synchronize (SYN) and acknowledge (ACK) each other. The exchange of these four flags is performed in three steps: SYN, SYN-ACK, ACK, as shown in Figure 5.8.

How is a socket established between a client and a server?

In a connection-oriented client-to-server model, the socket on the server process waits for requests from a client. To do this, the server first establishes (binds) an address that clients can use to find the server. When the address is established, the server waits for clients to request a service.


1 Answers

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).

like image 68
kanaka Avatar answered Sep 30 '22 10:09

kanaka