Difference between socket and websocket?

前端 未结 5 860
逝去的感伤
逝去的感伤 2020-11-28 17:36

I\'m building web app that needs to communicate with another application using socket connections. This is new territory for me, so want to be sure that sockets are differen

相关标签:
5条回答
  • 2020-11-28 17:54

    WebSocket is just another application level protocol over TCP protocol, just like HTTP.

    Some snippets < Spring in Action 4> quoted below, hope it can help you understand WebSocket better.

    In its simplest form, a WebSocket is just a communication channel between two applications (not necessarily a browser is involved)...WebSocket communication can be used between any kinds of applications, but the most common use of WebSocket is to facilitate communication between a server application and a browser-based application.

    0 讨论(0)
  • 2020-11-28 18:04

    Regarding your question (b), be aware that the Websocket specification hasn't been finalised. According to the W3C:

    Implementors should be aware that this specification is not stable.

    Personally I regard Websockets to be waaay too bleeding edge to use at present. Though I'll probably find them useful in a year or so.

    0 讨论(0)
  • 2020-11-28 18:06

    Websockets use sockets in their implementation. Websockets are based on a standard protocol (now in final call, but not yet final) that defines a connection "handshake" and message "frame." The two sides go through the handshake procedure to mutually accept a connection and then use the standard message format ("frame") to pass messages back and forth.

    I'm developing a framework that will allow you to communicate directly machine to machine with installed software. It might suit your purpose. You can follow my blog if you wish: http://highlevellogic.blogspot.com/2011/09/websocket-server-demonstration_26.html

    0 讨论(0)
  • 2020-11-28 18:09

    To answer your questions.

    1. Even though they achieve (in general) similar things, yes, they are really different. WebSockets typically run from browsers connecting to Application Server over a protocol similar to HTTP that runs over TCP/IP. So they are primarily for Web Applications that require a permanent connection to its server. On the other hand, plain sockets are more powerful and generic. They run over TCP/IP but they are not restricted to browsers or HTTP protocol. They could be used to implement any kind of communication.
    2. No. There is no reason.
    0 讨论(0)
  • 2020-11-28 18:11

    You'd have to use WebSockets (or some similar protocol module e.g. as supported by the Flash plugin) because a normal browser application simply can't open a pure TCP socket.

    The Socket.IO module available for node.js can help a lot, but note that it is not a pure WebSocket module in its own right.

    It's actually a more generic communications module that can run on top of various other network protocols, including WebSockets, and Flash sockets.

    Hence if you want to use Socket.IO on the server end you must also use their client code and objects. You can't easily make raw WebSocket connections to a socket.io server as you'd have to emulate their message protocol.

    0 讨论(0)
提交回复
热议问题