Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using web-sockets with Angular4?

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

Set Up:

  1. .NET Core Web API for API access
  2. List item

MS SQL DB for the database

like image 795
wonderful world Avatar asked Jun 30 '17 19:06

wonderful world


People also ask

Does angular support WebSockets?

The WebSocket API allows us to communicate between client and server through messages and event-based responses. Its implementation in an Angular project can be done through services and interfaces that allow the connection and management of messages.

How do I use RXJS WebSockets?

You can use wss for secure websocket connection. import { webSocket } from "rxjs/"webSocket; const subject = webSocket("ws://localhost:8081"); This way you have a ready to use subject that you should subscribe to in order to establish the connection with your endpoint and start receiving and sending some data.

Is socket IO compatible with WebSocket?

Although Socket.IO indeed uses WebSocket for transport when possible, it adds additional metadata to each packet. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a plain WebSocket server either.


1 Answers

Angular doesn't offer a special object to support WebSockets. But the good news is that WebSocket is supported by all browsers, and you can use it in your Angular4 apps. In this app I was using the ws package on the server (Node.js)and the browser's WebSocket object on the client (see https://github.com/Farata/angular2typescript/blob/master/Angular4/auction/client/src/app/product-detail/websocket.service.ts)

like image 171
Yakov Fain Avatar answered Oct 14 '22 16:10

Yakov Fain