From 984dbef933af0544e7c2a046058f5493c08b94fc Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Thu, 1 Apr 2010 23:07:29 -0700 Subject: [PATCH] add a quick usage example to README --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index 7f1c645..68e3f1c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,45 @@ 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');
+}
+
+ + License =======