What's the main difference between bidirectional and directional sockets?

后端 未结 2 655
离开以前
离开以前 2021-01-11 15:54

Bidirectional means the data incoming and outgoing data flows over the same channel (sockets), in classical socket it is the case. For example you want to c

2条回答
  •  余生分开走
    2021-01-11 16:16

    Websockets are an attempt to work around the pull model of HTTP, e.g. where the client does an HTTP query and the server does an HTTP response and that's the end of the talk. But often more than that is needed, e.g. server push or just classical bidirectional communication not limited to request+response. In a world without firewalls, one would use classical sockets for this task, but in today's world lots of communication is restricted and direct connections to arbitrary ports will not work anymore.

    Websockets work around this problem by upgrading an established HTTP communication. E.g. the client requests an HTTP upgrade, and if the server agrees both can talk from now on inside this HTTP connection like they would do with a simple TCP connection. In reality, they have some framing and data mangling inside, but this detail is hidden from the user. In a way, it is similar to the CONNECT method used by browsers to establish an (https) tunnel through a web proxy.

    Of course, this means that a Websocket connection can only be established between a web client supporting the protocol (most recent browsers do) and a web server implementing Websockets. This especially means that you cannot use WebSockets to connect to UDP sockets or to arbitrary TCP sockets (unless the web server forwards these data). But this also means, that if you upgrade an HTTPS connection to WebSockets, the WebSockets connection will be transparently SSL protected too. But, even if the client and server are supporting Websockets the connection upgrade might fail, if there is a web proxy in between which does not understand WebSockets or will explicitly block them.

    In case you understand german https://blog.genua.de/blog/post/loecher-in-der-firewall-mit-websockets.html might give you an interesting read about how Websockets fit in the network stack and about their security implications.

提交回复
热议问题