I don't know what possibly could have change, but my client/server communication with socket.io stopped working. Here is my server app :
io.sockets.on('connection', (socket) => {
console.log('user connected');
consumer.on('message', function (message) {
console.log(message);
io.sockets.emit("message",message);
});
});
The message are printed in the console. The consumer is a Kafka consumer but this shouldn't matter. Here is my client component:
this.connection = this.streamService.getMessages().subscribe((message: string) => {
console.log("Receiving message " + message);
}
Here is my client service:
getMessages() {
let observable = new Observable(observer => {
this.socket = io.connect(this.url);
this.socket.on('message', (data: any) => {
console.log(data);
observer.next(data.value);
});
return () => {
this.socket.disconnect();
};
})
return observable;
}
None of my client side log are displayed except "user connected". I get a Get request to http:/localhost:3000/socket.io/ frequently. Both client and server use "socket.io-client": "^2.0.1".
Thank you for your help!
via GrinnS
No comments:
Post a Comment