Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

WebSockets for Cappuccino

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 TestHarness
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CPWebSocket.j
Octocat-spinner-32 README.md
README.md

CPWebSocket

A WebSocket implementation for Cappuccino.

Test it out by running runserver.js from node.websocket (with Node) and then browsing to TestHarness/index.html with a browser that supports WebSockets (such as Google Chrome).

Usage

The API is very simple, like the native API. You can only open, close, and send messages with CPWebSocket. When you instantiate CPWebSocket you pass in a delegate that implements a few methods.

A short example:

// In a method somewhere

// ...
var webSocket = [CPWebSocket openWebSocketWithURL: @"ws://localhost:8080" delegate: self]
// ...

// in the delegate implementation:

- (void)webSocketDidOpen: (CPWebSocket)ws
{
    CPLog('web socket open: ' + [ws URL]);
}

- (void)webSocket: (CPWebSocket)ws didReceiveMessage: (CPString)message
{
    CPLog('web socket received message: ' + message);
}

- (void)webSocketDidClose: (CPWebSocket)ws
{
    CPLog('web socket closed');
}

- (void)webSocketDidReceiveError: (CPWebSocket)ws
{
    CPLog('web socket error');
}

// ...
// somewhere else
// ...

    [webSocket send: @"Hey, this is pretty slick!"];

License

Copyright 2010 Sami Samhuri

MIT License

Something went wrong with that request. Please try again.