Forums - C# Corner

Forum guidelines
Karthikeyan K

Karthikeyan K

  • 323
  • 5.5k
  • 731.4k

Angular with web socket

May 9 2018 1:10 AM
Can any help me, im not getting continous data from web socket, its giving only on first call
 
import { Injectable } from '@angular/core';
import * as io from 'socket.io-client';

@Injectable()
export class SocketService {
private _baseUrl = 'http://kaboom.rksv.net/watch';
private socket: SocketIOClient.Socket;
constructor() {
}

socketInit = () => {
this.socket = io.connect(this._baseUrl, {
transports: ['websocket', 'polling'],
forceNew: true,
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: Infinity
});
this.socket.on('connect', () => {
this.socket.on('data', (data) => {
console.log(data);
});
});
this.socket.on('disconnect', function () {
console.log('disconnected from server');
});
this.socket.on('error', (err) => {
console.log(err);
});

}

sub = () => {
this.socket.emit('sub', {
state: !0
});
}

}
 

Answers (4)