I'm writing a multilayer card game (like hearthstone) with Nodejs back-end and an angular front-end.
I tried to connect the two with Socket.IO, but it turned out that if I send a JSON object over about 8000char(the gameState object), then the client just keeps disconnecting and reconnecting.
If I only send the substring of 6000 char of the object everything is fine, but it crashes over 8000(I need about 20 000)
I have only tried in localhost
Here is the backend:
constructor() {
this.app = express();
this.port = process.env.PORT || ChatServer.PORT;
this.server = createServer(this.app);
this.io = socketIo(this.server);
this.gameService = new GameService();
this.listen();
}
listen(): void {
this.server.listen(this.port, () => {
console.log('Running server on port %s', this.port);
});
this.io.on('connect', (socket: any) => {
console.log('Connected client on port %s.', this.port);
socket.on('message', (m: string) => {
console.log('[server](message): %s', JSON.stringify(m));
this.io.emit('message', JSON.stringify(this.gameService.getGameState()).substring(1, 6000));
});
socket.on('disconnect', () => {
console.log('Client disconnected');
});
});
}
Edit:It works perfectly well with ajax, but I would need sockets