S
S
Semyon Kataparov2016-03-27 21:23:30
JavaScript
Semyon Kataparov, 2016-03-27 21:23:30

What is the problem of passing data to the server via socket.io?

What is the problem of passing data to the server via socket.io?
Server code:

socket.on('user_info', function(username){
    console.log('username: ' + username);
 });

Client code:
socket.on('connect', function (data) {
  console.log(username);
  if(username != 1) {
      socket.emit('user_info', { username : username});
  }
  else {
      console.log('Cant autheticate: You are not logged in.');
  }
});

Outputs: username: [object Object]
Should have been a name, console.log(username); - prints to the console

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2016-03-27
@truexizt1

you pass in an object... you
try to output it as a string....
...
you get what it is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question