• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    C
  • Created over 13 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Web Socket Server and Client Library for iOS and OSX. Follows Core Foundation API style.

CoreWebSocket - Core Foundation based WebSocket Library for iOS/OSX

CoreWebSocket is an C language, Core Foundation based library for iOS and Mac OSX. It can be used from Objective-C.

WebSocket enables low latency, bi-directional, full-duplex communication channel over TCP with web browser. It works with all modern web browsers including Safari, Chrome, Firefox and Opera. It works with iOS Safari as well.

Installation

To get the library using git in your project:

git submodule add git://github.com/mirek/CoreWebSocket.git CoreWebSocket

Then to add the library to your project

  1. Add CoreWebSocket.xcodeproj to project
  2. In to targets Build Phases
    1. In Target Dependencies add
      • CoreWebSocket
    2. In Link Binary With Libraries add
      • CFNetwork.framework
      • CoreServices.framework
      • libcrypto.dylib
      • CoreWebSocket.framework
    3. Add Build Phase > Add Copy Files
      1. Set Destination to be Frameworks
      2. Add CoreWebSocket.framework
  3. Clean
  4. Build CoreWebSocket
  5. Build your app

Usage

Exmaple AppDelegate.m

#import "AppDelegate.h"
#include "CoreWebSocket/CoreWebSocket.h"

@implementation AppDelegate

void Callback(WebSocketRef self, WebSocketClientRef client, CFStringRef value) {
    if (value) {
        CFShow(value);
    }
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    WebSocketRef webSocket = WebSocketCreateWithHostAndPort(NULL, kWebSocketHostAny, 6001, NULL);
    if (webSocket) {
        webSocket->callbacks.didClientReadCallback = Callback;
    }
}

@end

Web Browser Usage

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <script type="text/javascript" charset="utf-8">

      // WebSocket
      var ws = null;

      // When the page is loaded...
      window.addEventListener('load', function(e) {

        // Check if the browser supports WebSockets...
        if ("WebSocket" in window) {
  
          // ...it does, let's connect to localhost default port.
          // Make sure Quartz Composer composition is running with
          // the WebSocket Patch set to port 60001. 
          ws = new WebSocket('ws://localhost:60001');
    
          // Invoked when there was an error with the connection. 
          ws.onerror = function(e) {
            console.log('error', e);
          }
    
          // Invoked when the socket has been opened successfully.
          ws.onopen = function(e) {
            console.log('open', e);
          }
    
          // Callback invoked when incoming messages arrive. Event `data` attribute
          // holds the string passed. WebSocket in current spec supports utf8 text-based
          // communication only. Binary data  is base64 encoded.
          ws.onmessage = function(e) {
            var json = JSON.parse(e.data);
            console.log('message', json);
          }
    
          // Invoked when the socket has been closed
          ws.onclose = function(e) {
            console.log('close', e);
          }
    
        } else {
  
          // ...seems like the web browser doesn't support WebSockets.
          alert('WebSocket not supported by your browser, use Safari, Chrome or Firefox');
    
        }
      }, false);

    </script>
  </head>
</html>

License

Unless otherwise stated, the code is released under Open Source MIT License, (c) Copyright Mirek Rusin <mirek [at] me [dot] com>

Parts of the source code (particularly Base64 encoding functions) have been copied from http://opensource.apple.com which are released under Apple Public Source License 2.0 http://www.opensource.apple.com/apsl.

Portions of the copied source code could be modified.

More Repositories

1

YAML.framework

Proper YAML support for Objective-C. Based on recommended libyaml.
HTML
244
star
2

node-rus-diff

JSON diff
CoffeeScript
125
star
3

node-unused-deps

Report unused npm packages in node, es6, babel or coffee project.
CoffeeScript
79
star
4

CoreJSON

Core Foundation, libyajl based JSON support.
C
49
star
5

quartzcomposer-websocket

Quartz Composer WebSocket Plug-In
Objective-C
40
star
6

CoreSQLite3

Core SQLite3 for iOS and OSX. Fast. Clean. Powerful...
C
37
star
7

rb_tree

Red-black tree C implementation
36
star
8

node-json-criteria

Criteria queries on JSON objects Mongo style
JavaScript
33
star
9

INI.framework

Ini style file read/write support with format preserving
Objective-C
25
star
10

node-json-hash

JSON hash
JavaScript
24
star
11

NSMutableDictionary-REST.framework

REST category for NSMutableDictionary - the way it should be done.
Objective-C
24
star
12

quartzcomposer-opencv

OpenCV 2.1 port for Quartz Composer
Objective-C
19
star
13

quartzcomposer-objective-c

Objective-C/C/C++ for Quartz Composer (on the fly)
Objective-C
16
star
14

quartzcomposer-exporter

Quartz Composer Movie Exporter Plug-In
Objective-C
13
star
15

quartzcomposer-vnc

Quartz Composer VNC Server Plugin
C
11
star
16

CoreOSC

Open Sound Control - iOS/OSX Framework
C
6
star
17

flovv

flovv.org engine similar to quartz composer.
C++
5
star
18

GitHub.framework

Objective-C Framework for GitHub (API v.2)
5
star
19

sqlite-amalgamation

Contains all C source code for SQLite 3.7.10 combined into a single source file .
C
4
star
20

node-pg-safe-numbers

Safe number parsing for pg and Sequelize.
JavaScript
3
star
21

CoreMono

Embed C# in your Objective-C iOS and Mac OSX projects. Yey!
C
3
star
22

oscpads

OSCpad - advanced iPad OSC controller
JavaScript
3
star
23

node-flat-flow

Tiny flow.
CoffeeScript
3
star
24

CoreTestAllocator

Core Foundation Test Allocator to spot memory leaks
C
2
star
25

node-tiny-sse

Server Sent Events (SSE) for express/connect.
CoffeeScript
2
star
26

ruby-odbc

Clone of http://www.ch-werner.de/rubyodbc + fixes
C
2
star
27

libeio

C
1
star
28

node-flovv

nodejs based flovv prototype
1
star
29

libeio-old

http://software.schmorp.de/pkg/libeio.html with some changes (autogen warnings fixed, extended attributes support)
C
1
star
30

atom-html2jade

Convert HTML to jade
CoffeeScript
1
star
31

celldb

Ruby
1
star
32

mirek.github.com

mirek.github.com
1
star
33

db-logic

Ruby on Rails database logic support
Ruby
1
star
34

atom-special-snippets

Special characters cmd-⌘, shift-⇧, opt-βŒ₯, del-⌫, esc-βŽ‹, etc.
CoffeeScript
1
star