mirror of
https://github.com/samsonjs/cpwebsocket.git
synced 2026-04-27 15:07:39 +00:00
add a quick usage example to README
This commit is contained in:
parent
7c5c87a001
commit
984dbef933
1 changed files with 39 additions and 0 deletions
39
README.md
39
README.md
|
|
@ -10,6 +10,45 @@ TestHarness/index.html with a browser that supports WebSockets (such
|
||||||
as Google Chrome).
|
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:
|
||||||
|
|
||||||
|
<pre><code>// 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');
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue