Reputation: 1
I'm using the Unitt library (http://code.google.com/p/unitt/wiki/UnittWebSocketClient) to attempt to establish a connection to a local server via WebSockets within my iOS (iPhone) application.
I've successfully configured the project and am including the necessary project files, yet for some reason I cannot establish a simple connection. The code I am using is:
in SomeWebsocket.m:
WebSocketConnectConfig* config = [WebSocketConnectConfig configWithURLString:@"ws://localhost" origin:nil protocols:nil tlsSettings:nil headers:nil verifySecurityKey:YES extensions:nil ];
config.closeTimeout = 15.0;
ws = [WebSocket webSocketWithConfig:config delegate:self];
[ws open];
in SomeViewController.m:
MyWebSocket* myWS =[[MyWebSocket alloc] init]; [myWS startMyWebSocket];
Unfortunately, when I run the script, the only output is, [via console/NSLog],:
Oops. An error occurred.
Oops. It closed.
The only thing I can think of is that, when attempting to perform the handshake/login, I'm not sending some additional information that I should be. The server, for example, expects a username among other things. Could this be the problem, or perhaps it's something unrelated?
I've been working on this for quite some time and I can' figure it out, so I would definitely appreciate any help. Thanks.
EDIT: With no changes, I'm now also getting errors like so:
* Assertion failure in -[AsyncSocket doCFReadStreamCallback:forStream:], /Users/jmorris/Projects/xCode/UnitT/UnittWebSocketClient/trunk/UnittWebSocketClient/AsyncSocket.m:2811
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: theReadStream != NULL'
Upvotes: 0
Views: 1100
Reputation: 473
WebSocketConnectConfig* config = [WebSocketConnectConfig
configWithURLString:kWebsocketURL
origin:nil
protocols:nil
tlsSettings:nil
headers:nil
verifySecurityKey:YES
extensions:nil];
config.closeTimeout = -1;
config.timeout = -1;
// config.keepAlive = 5.0; //send ping from the server to keep socket alive
WebSocket *ws1 = [WebSocket webSocketWithConfig:config delegate:shared];
This is the code that I am using and it works fine. I had problems with stoppingtimer so, i dont ping from the client but just from server side.
Upvotes: 1
Reputation: 5842
You should try SocketRocket, a WebSocket library we just released. Supports RFC 6455 (latest standard). No CocoaAsyncSocket dependencies.
Upvotes: 1
Reputation: 266
Do you know what version of the web socket specification the server is running? I expect that your client version and your server version are experiencing a mismatch. It is only in the later versions of the specification that there is a clear way to communicate and handle such things. I am working on an update to the latest rev, but the holidays have made such things a bit challenging as of late. :)
Upvotes: 2