How to connect socket.io in angular 10?

Viewed 717

I'm using socket.io-client with @types/socket.io-client in angular 10

 import * as io from 'socket.io-client';

 private socket;
 private url = 'https://chat.domain.com';

 ngOnInit(): void {

    this.socket = io(this.url);
    console.log("socket =============>>",this.socket);
}

But every time got the same error see the below response

enter image description here

Someone, please help me

1 Answers
 npm install socket.io-client@2.3.0

 import io from 'socket.io-client';

 this.socket = io("http://localhost:8080", {});
  
 console.log(this.socket);

You have to install the client-side socket version and the server-side socket version needs to be the same.

Related