pkyeck / socket.IO-objc

socket.io v0.7.2 — 0.9.x for iOS and OS X
MIT License
1.97k stars 439 forks source link

Trying to get socket.IO-objc to work with socket.io's chat example #229

Closed headstream12 closed 7 years ago

headstream12 commented 7 years ago

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?

pkyeck commented 7 years ago

The phpsocket.io repo only supports socket.io v1.3.0 or greater. But this library only supports socket.io < 1.0.0 - so that is the problem.

headstream12 commented 7 years ago

I use library, which full supports socket v1 and > This library has 2 variants. One without support v 1, another with

pkyeck commented 7 years ago

I don't understand - if you use this lib, it doesn't support version >= 1.0. If you use a different lib, than why are you posting an issue here?