ioswebsocketsocketrocket

iOS WebSocket not connecting to Server using SocketRocket


I'm creating a chat application whose WebSocket server is written in java.
For WebSocket client i'm using SocketRocket library.

Everything works fine when i try to connect from localhost or 127.0.0.1.
But when i try to connect it using the public IP, it gives following error in - (void) webSocket:(SRWebSocket *)_webSocket didFailWithError:(NSError *)error method:

Error Domain=NSPOSIXErrorDomain Code=57 "The operation couldn’t be completed. Socket is not connected"

Here is how i initialize the SRWebSocket object:

webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:@"ws://IP_ADDRESS:8080/ChatWebSocket/chat/12345"]];  
// connects successfully when IP_ADDRESS = localhost or 127.0.0.1 
// gives 'Socket is not connected' error when IP_ADDRESS = some public IP address

I've also tried initializing SRWebSocket with initWithURLRequest:.

P.S i've also tested and verified that the WebSocket server is accessible by its public IP address from a javascript code.

Therefor i think the issue is at the client end.

Any help will be appreciated.
Thanks in advance


Solution

  • After almost 2 days of research, i finally realized that the problem was arising on simulator only.
    When i tested the same code on an iPod touch, it worked like a charm! :)