Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a web-service and web-socket

As I mentioned in the title: I would like to know the difference between the web-service and the web-socket? when we used each one?

Thanks!

like image 515
user1444393 Avatar asked Jul 29 '14 20:07

user1444393


People also ask

Is WebSocket a Web service?

The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

What is difference between WebSocket and API?

APIs are the best option for applications where you just need basic CRUD operations and synchronous responses. Also, APIs can be used with both web and mobile applications and service integrations with ease. But, if your web application requires real-time communication with the backend, you should choose WebSockets.

What is difference between WebSocket and HTTP?

Unlike HTTP, where you have to constantly request updates, with websockets, updates are sent immediately when they are available. WebSockets keeps a single, persistent connection open while eliminating latency problems that arise with HTTP request/response-based methods.

Is a WebSocket an API?

The WebSocket API invokes your backend based on the content of the messages it receives from client apps. Unlike a REST API, which receives and responds to requests, a WebSocket API supports two-way communication between client apps and your backend. The backend can send callback messages to connected clients.


2 Answers

A web service is an HTTP server that responds to client SOAP/REST/JSON requests.

A web socket is a client-side API that allows a web browser to create a bidirectional communication link with a server without having to change/reload the current page. This is typically used for AJAX requests to dynamically update live content on the current page, or create chat sessions between clients, or implement custom protocols that run in the web browser.

like image 112
Remy Lebeau Avatar answered Oct 18 '22 00:10

Remy Lebeau


Web services are based on HTTP protocol and use HTTP methods to relay data in a request and response paradigm. Thus the client will always be the one responsible for communicating with the server, requesting data and submitting data to the server i.e getting list of customers or products, adding products or customers to server.

In contrast, Web sockets allow bidirectional communication, meaning server can initiate communication as much as client can do the same. Typically you supply a host IP Address and port to the socket. Web sockets can be used to implement a chat application.

The key difference between Web sockets and Web services is that with web sockets you get bi-directional connection in which the server and client can continuously send messages back and forth while Web services are uni-directional connection concerned with supplying clients with resources

like image 5
ABODE Avatar answered Oct 17 '22 23:10

ABODE