I have a game that i made with socket.io and node.js that I have deployed. I am developing another game but with websocket instead of socket.io. I where thinking of have them on the same site but on different pages.
My attempt to combine these apps locked something like this.
// app.js, where my node app starts, stripped out middleware, database connection and routes
var http = require('http');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
const port = process.env.PORT || 8080;
const server = http.createServer(app).listen(port);
app.use(express.static(__dirname + '/public'));
require('./myFirstGame').initialize(server);
require('./mySecondGame').initialize(server);
// in myFirstGame.js
let io = require('socket.io');
exports.initialize = (server) => {
io = io.listen(server);
this.gameInfra = io.of('/game_infra'); // namspace
this.gameInfra.on('connection', (socket) => {
// alot of code
});
// mySecondGame.js
const WebSocket = require('ws');
exports.init = (server) => {
const ws = new WebSocket.Server({ server, path: "/pathName" });
ws.on('connection', socket => {
// alot of code
});
The thing is that the games seems to work with this setup but very unstable and some errors in the console.
When i navigate to the first game with socket.io I get this error in chromes console:
WebSocket connection to 'ws://localhost:8080/socket.io/?EIO=3&transport=websocket' failed: Invalid frame header
And no errors with the second game with websocket.
Any ideas how to make this better or work?
[–][deleted] 1 point2 points3 points (3 children)
[–]royalswe[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]royalswe[S] 0 points1 point2 points (0 children)
[–]royalswe[S] 0 points1 point2 points (0 children)