last day (15 days later) » 

8:26 PM
1
Q: socket io does not sending data

Alexi am setting up a new server, which its sending the x and y value of a rectangle on a game field but it does not working at all. since the server runs i cannot see the {x: y:} object printed on the console this is my update function of the square function update() { switch(gameState.direct...

 
could you please explain further?or a suggested update of my code which it works please?
 
The "quick and easy" fix is to just change io.sockets.on('connection'... to io.on('connection'...
^ He meant to use that as part of his console.log statement (it should be sommented out)
 
@RichS after your change i am getting a" bad post request" :( socket.io-1.0.0.js:1 POST localhost:3000/socket.io/… net::ERR_CONNECTION_REFUSED
 
To avoid confusion with how variables are named, move the require('socket.io') statement down, and set var io = require('socket.io')(server). Then comment out that require statement on the second line. It works for me.
On the front end, it's usually a good idea to also have a connect listener set up...so you only emit after connected...i.e., on the front end, you'll want socket.on('connect', () => console.log('connected'))
 
@RichS could you please add your whole try on my code as Answer below ?
 
8:26 PM
Please check out my fiddle. I'll post as an answer once verified. Server Side code || Client-side code
 
its working thanks a lot :)
@RichS do you know what this error means please ? :Uncaught ReferenceError: Cannot access 'socket' before initialization
hello
 
it depends where you're trying to use socket
is that on client or server?
 
client
 
ok, just try moving the const socket line to the top: like here: jsfiddle.net/bkcza5t0/2
 
// Your code from previous exercise here
let frameCount = 0;
let fps, frameTime, startTime, now, then;
//////////////////////////////////
function startAnimating(targetFPS) {
frameTime = 1000 / targetFPS;
then = window.performance.now();
startTime = then;
frameCount = 0;

animate(then);
}
///////////////////////////////
function animate(currentTime) {

if (frameCount < 10) {
window.requestAnimationFrame(animate);
}
now = currentTime;
const elapsed = now - then;
if (elapsed > frameTime) {
then = now;
this is my whole code
i have the same error
 
8:32 PM
move the connect statement all the way to the top... because you're calling update before it.
like, line 1 of ALL your code
 
the same error
does it work with you?
 
please repost code as you have it. please post into jsfiddle.net
 
it has been crashed
it does not work at all
 
8:41 PM
try again with this: jsfiddle.net/6pf0umd4/3
 
the update function does not invoked at all :(
 
do you get socket connect ok? in the console?
 
no this one snake2.js:1 Uncaught ReferenceError: io is not defined
at snake2.js:1
and the square does not appear
on the browser
 
last thing to try for now, then I gotta run: jsfiddle.net/6pf0umd4/4
 
ok thanks a lot
 
8:48 PM
any luck?
did it work?
 
no i canot see the square
:(
it does not work at all
 
do you get the socket connect ok?
 
no
no thing like this
 
i gotta run.
 
ok thanks
 

last day (15 days later) »