A conforming Objective-C WebSocket client library.

SocketRocket After trying to install socketrocket so that I can make PonyDebugger work, I'm getting 3 Apple Match-O linker errors

I'm getting the fllowing. It's my first time trying to install this and I have to since I need the Pony Debugger working.

Undefined symbols for architecture i386:
  "_utf8_countTrailBytes", referenced from:
      _validate_dispatch_data_partial_string in libSocketRocket.a(SRWebSocket.o)
  "_utf8_nextCharSafeBody", referenced from:
      _validate_dispatch_data_partial_string in libSocketRocket.a(SRWebSocket.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any advice is very much appreciated!


EDIT: I added the SocketRocket.Framework to the build Phases and the errors are gone but is now giving me a new one.


The new one doesn't make sense at all.

Source: (StackOverflow)

Library not found Error when simple building web socket chat in iOS?

i downloaded simple web socket chat code and am getting this error

  ld: library not found for -lPods-SocketRocket
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Please anyone tell me how to solve this?

In my other linker flags contains these things


My code

Source: (StackOverflow)

Implementin SRWebSocketDelegate in Swift

I am implementing:

@protocol SRWebSocketDelegate <NSObject>

- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;


- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;

in Swift. All functions I can implement ok and works, but didCloseWithCode I just can't make it to work.

I am having trouble implementing

- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;

in Swift.

I am trying:

func webSocket(webSocket: SRWebSocket!, didCloseWithCode code: NSInteger!, reason: NSString!, wasClean: Bool!) {
    println("websocket closed: \(reason)")

with no luck.

Source: (StackOverflow)

Why does my websocket server always report [websocket: control frame length > 125]?

My iOS application uses SocketRocket to establish a connection with my websocket server. But after establishing a connection and sending the first message, the server (using gorilla/websocket) tries to parse the frame, but failed:

message_type, r, err := ws.NextReader()
if err != nil {
    goto end

An error is reported when calling NextReader():

Websocket Read Failed: [websocket: control frame length > 125]

The strange thing is, I use SocketRocket's send() method to send data, so there should never be any control frames (ping/pong).

Has anyone seen this problem before? Help!

Source: (StackOverflow)

How to use SocketRocket with

The new iOS websocket library, SocketRocket, looks really awesome, and the chat example project is really sweet. The example chat server is written in Python, of which I know none. I'm slightly familiar with on node.js and prefer to try javascript. I tried connecting the SocketRocket TestChat simulator app to the node.js(6.10) but the connection was refused. (Also, I'm not a node expert either, so this may be a silly question).

In a recent answer to an SO question, mikelikespie said to op: "I suggest updating your stack to use the iOS WebSocket library we just released."

What does that mean exactly? What is necessary to get the SocketRocket library to talk to a node server? Any sample code or suggestions are greatly appreciated.

Source: (StackOverflow)

Using to connect to Nodejs server on iOS7 [closed]

I'm trying to connect my iOS7 app to a nodejs server. I've been researching for a lot of things yet nothing seems clear enough, here is my understanding of things. I need a server and a client to communicate through websockets, my server uses nodejs and ,my client however is where the struggle begins, I'm not sure what library am I supposed to use (SocketRocket, the difference anyway?)? A little explanation would be appreciated. I couldn't get my hands on anything iOS7 related either so if there happened to be a nice tutorial for this, please share.

Source: (StackOverflow)

Any server that I can run locally in iOS that is compliant with SocketRocket?

Is there a server that I can run inside an iPhone app (a localhost server running in iOS) that can talk to SocketRocket? I know CocoaHTTPServer comes bundled with a server and a websocket implementation. But I wish to use a different websocket library in IOS.

Source: (StackOverflow)

Difference between UnittWebSocketClient library and SocketRocket. Which one is efficient to use?

Difference between UnittWebSocketClient library and SocketRocket. Which one is efficient to use to implement WebSockets in iOS Apps?

Source: (StackOverflow)

Apple Mach-O Linker Error with the introduction of SocketRocket

I'm using Xcode Version 6.0.1 (6A317)and stuck with Apple Mach-O error for a long time. I get this error once I introduce SocketRocket project.

duplicate symbol _OBJC_IVAR_$_AppDelegate._window in:

duplicate symbol _OBJC_METACLASS_$_AppDelegate in:
duplicate symbol _OBJC_CLASS_$_AppDelegate in:
duplicate symbol _OBJC_CLASS_$_ViewController in:
duplicate symbol _OBJC_METACLASS_$_ViewController in:
duplicate symbol _main in:
ld: 6 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have made sure to follow the steps given in

the only exception I see is SocketRocket.framework was showing red when I tried adding it under + Link Binary with libraries.

I have added the following libraries:


I've set other linker flags to -ObjC Build Active Architecture only - No, because setting it to Yes throws an error : Check dependencies. No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386). Valid Architectures - armv64 armv7 armv7s

This issue is really killing my time. I tried to follow other posts but nothing could help me solve the issue!

Source: (StackOverflow)

Sending a UILocationNotification from the background

I have an app where I need to send a UILocationNotification when the app is not in the foreground / Active. If I have my code to do so, it will not send until the app is opened and is active.

Here is my function:

- (void)setLocalNotificationForType:(SPKLocalNotificationType)notificationType fromUser:(NSString *)userName withMessageText:(NSString *)msgText {

    UILocalNotification *notif = [[UILocalNotification alloc] init];
    notif.userInfo = @{@"handle": _convoHandle, @"room": _convoName};
    notif.fireDate = [NSDate date];
    notif.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
    notif.soundName = UILocalNotificationDefaultSoundName;
    notif.timeZone = [NSTimeZone defaultTimeZone];

    if (notificationType == 1) { // message
        notif.alertBody = [NSString stringWithFormat:@"@%@ said: \"%@\"", userName, msgText];
    } else if (notificationType == 2) { // image
        notif.alertBody = [NSString stringWithFormat:@"@%@ sent an image", userName];
    } else {

    if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
        [[UIApplication sharedApplication] presentLocalNotificationNow:notif];

Update: It now seems that the problem is that the connection to the server is being "paused" while the app is in the background. Once I then open the app all the data comes in at once. I am using SocketRocket for connecting to my Node.js Primus web socket server. Is this something that normally happens? This is my first time using SocketRocket so I'm not sure.

Update: I have also enabled Remote Notifications for Background Modes, I have also registered for remote notifications, and on the device, I have also made sure that "banners" and "badges" are enabled.

Update: I have additionally set the web socket to use a background queue.

[webSocket setDelegateOperationQueue:[NSOperationQueue new]];

The connection is still being paused.


Source: (StackOverflow)

Web Socket: cannot detect client connection on internet disconnect

I want to detect the client connection if client turn off the internet using web socket. My code is:

 //Include util library
    var util = require('util');
    // Include underscore library
    var _ = require('underscore')._;
    //For websocket
var webSocketServer = new (require('ws')).Server({port: (process.env.PORT || 5000)}),
webSockets = {} // userID: webSocket

// CONNECT /:userID
// wscat -c ws://localhost:5000/1
webSocketServer.on('connection', function (webSocket) 
  var userID = webSocket.upgradeReq.url.substr(1);
  //console.log('User_id is ',userID);
  webSockets[userID] = webSocket
                   util.log('User_id: [' + userID + '] enter in connected users list of [ ' + Object.getOwnPropertyNames(webSockets)+' ]')
                   // Call function which check id exist in letswalkee DB table

                   // Send msg like: [fromUserID, text]    [1, "Hello, World!"]
webSocket.on('message', function(message) {
util.log('Received from [' + userID + ']: ' + message)
var messageArray = JSON.parse(message)
                                    var toUserWebSocket = webSockets[messageArray[0]]
                                    if (toUserWebSocket) {
                                    util.log('Sent to [' + messageArray[0] + ']: ' + JSON.stringify(messageArray))
                                    messageArray[0] = userID

                   webSocket.on('close', function () 
                      delete webSockets[userID]
                      util.log('User_id Deleted from connected users: [ ' + userID+' ]');

   console.log('hello i am disconnected');  

I used that code (webSocket.on('disconnect',function()) but did not worked? Help asap?

Source: (StackOverflow)

Calling a delegate function and return result

Im doing a small test project with SocketRocket on ios. But i can't seem to wrap my head around the logic.

Here's the thing: I have need to have a sort of "global" function to call the sockets. When my app opens it should connect using the websockets.

_webSocket.delegate = nil;
[_webSocket close];

_webSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ws://localhost:12345/connectr"]]];
_webSocket.delegate = self;

self.title = @"Opening Connection...";
[_webSocket open];

However, i need to get the logic on connecting to a delegate function. I already thought of a singleton but i read that the singleton functions are quite cpu expensive.

So basically my question is: What is the best way to initiate a global accesable function that uses the (appdelegate) initalized SocketRocket instance.

Source: (StackOverflow)


I'm getting iOS EXC_BAD_ACCESS errors while using SocketRocket, and I wonder what I can do to further debug the issue to determine if the problem is on my side, or on SocketRocket's side.

The stacktrace I get is :

0    libobjc.A.dylib     objc_msgSend + 5
1    OMlearnings         SRWebSocket.m line 692    __30-[SRWebSocket _failWithError:]_block_invoke_2
2    libdispatch.dylib   _dispatch_call_block_and_release + 10
10   UIKit               UIApplicationMain + 1136
11   OMlearnings         main.m line 16    main

or sometimes

Crashed: NSOperationQueue Serial Queue
0    libobjc.A.dylib     objc_msgSend + 5
1    OMlearnings         SRWebSocket.m line 613    -[SRWebSocket scheduleInRunLoop:forMode:]
2    OMlearnings         SRWebSocket.m line 600    -[SRWebSocket _connect]
3    OMlearnings         OMSRealTimeTeamDashboard.m line 157    -[OMSRealTimeTeamDashboard sendMessage:]
4    OMlearnings         OMSRealTimeTeamDashboard.m line 171    -[OMSRealTimeTeamDashboard eventReceived:]
5    CoreFoundation      __invoking___ + 68
6    CoreFoundation      -[NSInvocation invoke] + 282
7    Foundation          -[NSInvocationOperation main] + 112
8    Foundation          -[__NSOperationInternal _start:] + 770
14   libsystem_pthread.dylib _pthread_wqthread + 298

My codebase is quite simple and basically subscribes to events, and executes socketrocket sendMessage in a queue (to deal with concurrency)

[signalServices subscribe:my-event toBlock:^(NSNotification * notification) {
    [this.queue addOperation:[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(eventReceived:) object:notification]];

- (void)eventReceived: (NSNotification *)notification {
    // ...
    [socket send:[NSString stringWithFormat:@"%i,1,%@", currentUserId.intValue, [NSNumber numberWithInt: rate.value]]];

I've read people using NSZombies to debug the issue, but my problem only happens rarely, so I would likely run out of memory before the problem becomes visible. It works fine 99% of the time.

Is there anything to know about iOS that could randomly crash apps that use sockets, etc ? For instance, we have background fetch enabled, could that be the cause of some of the random crashes ?

Thanks !

Source: (StackOverflow)

SocketRocket RunLoop sporadic crash

So our app has been experiencing crashes for a while in SocketRocket. We get about 20 crashes a day from it, with the following stack trace:


Thread : Crashed:
0  libsystem_platform.dylib       0x3b8ff816 spin_lock$VARIANT$mp + 1
1  CoreFoundation                 0x30e2d593 CFSocketEnableCallBacks + 54
2  CFNetwork                      0x30a926f9 SocketStream::securityBufferedRead_NoLock() + 212
3  CFNetwork                      0x30a925f5 SocketStream::socketCallbackReadLocked(SocketStreamSignalHolder*) + 76
4  CFNetwork                      0x30a90d8f SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*) + 102
5  CFNetwork                      0x30a90cf3 SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void const*, void*) + 58
6  CoreFoundation                 0x30e6a337 __CFSocketPerformV0 + 578
7  CoreFoundation                 0x30e68183 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
8  CoreFoundation                 0x30e67653 __CFRunLoopDoSources0 + 206
9  CoreFoundation                 0x30e65e47 __CFRunLoopRun + 622
10 CoreFoundation                 0x30dd0c27 CFRunLoopRunSpecific + 522
11 CoreFoundation                 0x30dd0a0b CFRunLoopRunInMode + 106
12 Foundation                     0x317be3db -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 254
13 Piazza                         0x00110b7b -[_SRRunLoopThread main]
14 Foundation                     0x31880c87 __NSThread__main__ + 1062
15 libsystem_pthread.dylib        0x3b904c1d _pthread_body + 140
16 libsystem_pthread.dylib        0x3b904b8f _pthread_start + 102

I've been trying to nail it down for over 20 hours. It's pretty sporadic - the best way I have of reproducing it is to log out, so the connections all fail, and then try to incite some connections, and/or wait for several minutes. Works about 1/4 of the time, after a few minutes. However, there are logs of people experiencing this crash while still logged in.

As far as the code, I can't tell what is causing the EXC_BAD_ACCESS, since all the entries above 13 have no available source, and looking at the assembly code hasn't really enlightened me much - all I've discovered is that ecx gets set to 0xc in the course of things, and then spin_lock$VARIANT$mp tries to swap some register for stuff located at ($ecx), and it crashes. [_SRRunLoopThread main], the only part of the stack trace I have source for, is as follows:

- (void)main;
    @autoreleasepool {
        _runLoop = [NSRunLoop currentRunLoop];

        NSTimer *timer = [[NSTimer alloc] initWithFireDate:[NSDate distantFuture] interval:0.0 target:nil selector:nil userInfo:nil repeats:NO];
        [_runLoop addTimer:timer forMode:NSDefaultRunLoopMode];

        int i = 0;

        while ([_runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) {

It crashes on the while line. I suspect that something, somewhere, is getting deallocated before it's supposed to, but I'm not sure if it's an SRWebSocket or somehow a block that was added to the run loop or what. I'm not totally familiar with run loops.

I'm running out of productive things to do to figure this out, and I've made barely any progress. Any help is appreciated.

Source: (StackOverflow)

SocketRocket and iOS certificate pinning

I'm currently using SocketRocket as the WebSocket implementation for my iOS applications and would like to pin my server's CA as a trusted certificate with the SR_SSLPinnedCertificates property. I'm looking for a good example of loading one or more certificates to pass into SocketRocket. I've got the following code to work but I'm not sure it's correct or if there is a more straight-forward approach.

CFArrayRef keyref = NULL;
NSString *path = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"p12"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
OSStatus status = SecPKCS12Import((__bridge CFDataRef)data, (__bridge CFDictionaryRef)[NSDictionary dictionaryWithObject:@"eftl_key_pass" forKey:(__bridge id)kSecImportExportPassphrase], &keyref);
if (status == noErr) {
    CFDictionaryRef identityDict = CFArrayGetValueAtIndex(keyref, 0);
    SecIdentityRef identityRef = (SecIdentityRef)CFDictionaryGetValue(identityDict, kSecImportItemIdentity);
    SecCertificateRef certRef = NULL;
    SecIdentityCopyCertificate(identityRef, &certRef);

Source: (StackOverflow)