Difference between the socket , socketio, and websockets

2,779

Solution 1

HTTP request is something like this, if we write something on the URL or search bar using a browser then

  1. Browser sends a request to the server that is HTTP request is made to the server.
  2. Server responds to the browser with some data.

This asks for something, get something kind of system works great for a huge variety of things, like reading the news or checking the weather.

But if you want to get info more real-time, like chatting you would have to be requesting all of the time.

Websocket's purpose is to allow for a persistent' connection with a backend server so that client doesn’t have to wait for another time as the browser does.

So anyone can create a backend and frontend combination system that can very quickly and responsively react to new data as if it were a stream flowing into your client (like web client, mobile app)

You have to write both server and client to achieve real-time applications and the client needs to be connected to the server.

If you want to make a video call application then you need to exchange some info like SDP, ICE Candidate, etc. So to exchange these informations you have to develop a signaling server so that server can send these informations in real-time to its respective client.

In every platform, you can achieve socket technology. So socketio, flask socket are the different forms of the same thing in different platforms.

Solution 2

A socket is one endpoint of a two-way communication link between two programs running on the network. This is a very low-level thing, everything else is implemented on top of TCP sockets.

WebSocket is a standard communication protocol for the web. It allows for a full-duplex communication channel to be established between a client and a server.

Socket.IO is a communication protocol that builds on top of HTTP and WebSocket, providing extra features such as automatic reconnection, event-based notifications, etc.

Flask-SocketIO is an implementation of the Socket.IO server-side protocol as a Flask extension.

To access a Socket.IO server from your flutter application you need to use a Socket.IO client. I do not use flutter myself, so I cannot recommend one.

Solution 3

In a nutshell, WebSockets are a thin transport layer built on top of a device’s TCP/IP stack. The intent is to provide what is essentially an as-close-to-raw-as-possible TCP communication layer to web application developers while adding a few abstractions to eliminate certain friction that would otherwise exist concerning the way the web works. They also cater to the fact that the web has additional security considerations that must be taken into account to protect both consumers and service providers. Ably's deep dive is a brilliant resource for getting to grips with websockets: http://go.ably.com/websockets

Socket.IO is a great tool for developers wanting to set up bi-directional socket connections between client and server. This makes simple applications such as live chat much simpler to implement. Socket.IO makes many things easier and provides fallbacks for unsupported clients, but has its own trade-offs. Ably also wrote a concept piece outlining Socket.IO main use cases and how to get started: http://go.ably.com/socketio

Share:
2,779
Atul Dubey
Author by

Atul Dubey

Updated on December 21, 2022

Comments

  • Atul Dubey
    Atul Dubey over 1 year

    Can someone explain me difference between socket, socketio, flask socketio with respect to python? And for using it this socket with flutter what code should I write on backend? Like I should write sever and client or only client?

  • Atul Dubey
    Atul Dubey almost 4 years
    Bro so I Have to write flutter code for the client part and backend code as flask socketIo? is it fine?
  • Shahnawaz Hossan
    Shahnawaz Hossan almost 4 years
    Yes, brother. Absolutely. I think you get it.
  • Atul Dubey
    Atul Dubey almost 4 years
    Thanks man It was helpful! So in the end i have to write code for flutter as socket client and flask socketio as server write?
  • Shahnawaz Hossan
    Shahnawaz Hossan almost 4 years
    Bro, if you would like to get started with flutter you can check this tutorial. Here backend server is made with nodejs. That doesn't matter, you can build it with flask as well.
  • Atul Dubey
    Atul Dubey almost 4 years
    Lol bro You are Best! I am mechanical enginneer so i dont have deep knowledge. But you solved my problem
  • Shahnawaz Hossan
    Shahnawaz Hossan almost 4 years
    Ha ha ha, my pleasure bro.
  • Pe Dro
    Pe Dro over 2 years
    Aren't "two-way communication" in socket and "full-duplex communication" in WebSocket the same ?
  • Miguel Grinberg
    Miguel Grinberg over 2 years
    @PeDro Yes. What is the point you are trying to make, though? A network socket is a low-level thing, WebSocket is a high-level protocol that uses network sockets.