Using web sockets with Angular4?

How can I use web sockets with Angular4? HttpModule does not support it, so is there an NPM package available that I can use?

Setup:

  • .NET Core API for Access APIs
  • List item

MS SQL DB for the database

+5
source share
4 answers

Angular does not offer a special object for supporting WebSockets. But the good news is that WebSocket is supported by all browsers, and you can use it in your Angular4 applications. In this application, I used the ws package on the server (Node.js) and the web browser object on the client (see https://github.com/Farata/angular2typescript/blob/master/Angular4/auction/client/src/app /product-detail/websocket.service.ts )

+3
source

One option is that you can always use Firebase (this btw is a very interesting option). Quite a lot makes you hard climb.

Otherwise, WebSockets is the HTML5 standard. You just need to write code to implement it. Browse this site, which has all the information, an echo demo / test, etc.:

https://www.websocket.org/

+1
source

You can use socket.io-client, just be sure to enable typing during installation.

https://www.npmjs.com/package/socket.io-client

Installation: npm install --save socket.io-client

and

npm install --save @types/socket.io-client or npm install --save-dev @types/socket.io-client

Note. There's a great tutorial out there that provides recommendations for a MEAN full-stack environment here , if that is interesting.

edit: As already mentioned, WebSocket is an HTML5 standard. This will simply create an easy-to-use interface for socket interface interactions and is applicable to any external environment.

+1
source

I use angular2 -websocket / angular2 -websocket in my angular project and it works very well https://github.com/afrad/angular2-websocket

0
source

Source: https://habr.com/ru/post/1269383/


All Articles