Tuesday, 6 June 2017

400 bad request (making game with node and socket.io)

Making a game, I have no idea what I am doing when it comes to the online aspect.

I am using node.js using my computer as the server host and client (localhost:3000)

var express = require('express'); //no idea what I am doing here
var app = express();
var server = app.listen(3000);
var socket = require("socket.io");
var io = socket(server);
io.sockets.on('connection', newConnection);
app.use(express.static("public"));

console.log("server is up"); //tells me that the server is ready

function newConnection(socket) {
    console.log("new player!", socket.id); //tells me when a new player connects.
}

also have this code within the main public javascript file

var socket;
socket = io.connect("localhost:3000");

Whenever a new player connects i get 400 bad request errors and the game thinks multiple players have joined.

picture to aid

so pls help.



via Canatron

No comments:

Post a Comment