I am using socket.io's chat example php based (https://github.com/walkor/phpsocket.io) , and I can receive messages. However, I can't send messages. While attempting to set the nickname, I get a crash on the node instance. On the iOS side, I send a message in the socketDidConnect method after my viewDidLoad method...
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.socketIO = [[SocketIO alloc] initWithDelegate:self];
self.socketIO.useSecure = NO;
[self.socketIO connectToHost:@"localhost" onPort:3000];
}
(void) socketIODidConnect:(SocketIO *)socket{
NSLog(@"We connected....");
[self.socketIO sendEvent:@"add user" withData:@"testUser"];
}
On the server side function add user:
// when the client emits 'add user', this listens and executes
$socket->on('add user', function ($username) use($socket){
global $usernames, $numUsers;
// we store the username in the socket session for this client
$socket->username = $username;
// add the client's username to the global list
$usernames[$username] = $username;
++$numUsers;
$socket->addedUser = true;
$socket->emit('login', array(
'numUsers' => $numUsers
));
// echo globally (all clients) that a person has connected
$socket->broadcast->emit('user joined', array(
'username' => $socket->username,
'numUsers' => $numUsers
));
});
How i can set username and send messages?