1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/com/codebutler/android_websockets/README.md Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,140 @@ 1.4 +# WebSocket and Socket.IO client for Android 1.5 + 1.6 +A very simple bare-minimum WebSocket and Socket.IO client for Android. 1.7 + 1.8 +## Credits 1.9 + 1.10 +The hybi parser is based on code from the [faye project](https://github.com/faye/faye-websocket-node). Faye is Copyright (c) 2009-2012 James Coglan. Many thanks for the great open-source library! 1.11 + 1.12 +The hybi parser was ported from JavaScript to Java by [Eric Butler](https://twitter.com/codebutler) <eric@codebutler.com>. 1.13 + 1.14 +The WebSocket client was written by [Eric Butler](https://twitter.com/codebutler) <eric@codebutler.com>. 1.15 + 1.16 +The Socket.IO client was written by [Koushik Dutta](https://twitter.com/koush). 1.17 + 1.18 +## WebSocket Usage 1.19 + 1.20 +```java 1.21 +List<BasicNameValuePair> extraHeaders = Arrays.asList( 1.22 + new BasicNameValuePair("Cookie", "session=abcd") 1.23 +); 1.24 + 1.25 +WebSocketClient client = new WebSocketClient(URI.create("wss://irccloud.com"), new WebSocketClient.Listener() { 1.26 + @Override 1.27 + public void onConnect() { 1.28 + Log.d(TAG, "Connected!"); 1.29 + } 1.30 + 1.31 + @Override 1.32 + public void onMessage(String message) { 1.33 + Log.d(TAG, String.format("Got string message! %s", message)); 1.34 + } 1.35 + 1.36 + @Override 1.37 + public void onMessage(byte[] data) { 1.38 + Log.d(TAG, String.format("Got binary message! %s", toHexString(data))); 1.39 + } 1.40 + 1.41 + @Override 1.42 + public void onDisconnect(int code, String reason) { 1.43 + Log.d(TAG, String.format("Disconnected! Code: %d Reason: %s", code, reason)); 1.44 + } 1.45 + 1.46 + @Override 1.47 + public void onError(Exception error) { 1.48 + Log.e(TAG, "Error!", error); 1.49 + } 1.50 +}, extraHeaders); 1.51 + 1.52 +client.connect(); 1.53 + 1.54 +// Later… 1.55 +client.send("hello!"); 1.56 +client.send(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }); 1.57 +client.disconnect(); 1.58 +``` 1.59 + 1.60 +## Socket.IO Usage 1.61 + 1.62 +```java 1.63 +SocketIOClient client = new SocketIOClient(URI.create("wss://example.com"), new SocketIOClient.Handler() { 1.64 + @Override 1.65 + public void onConnect() { 1.66 + Log.d(TAG, "Connected!"); 1.67 + } 1.68 + 1.69 + @Override 1.70 + public void on(String event, JSONArray arguments) { 1.71 + Log.d(TAG, String.format("Got event %s: %s", event, arguments.toString())); 1.72 + } 1.73 + 1.74 + @Override 1.75 + public void onJSON(JSONObject json) { 1.76 + try { 1.77 + Log.d(TAG, String.format("Got JSON Object: %s", json.toString())); 1.78 + } catch(JSONException e) { 1.79 + } 1.80 + } 1.81 + 1.82 + @Override 1.83 + public void onMessage(String message) { 1.84 + Log.d(TAG, String.format("Got message: %s", message)); 1.85 + } 1.86 + 1.87 + @Override 1.88 + public void onDisconnect(int code, String reason) { 1.89 + Log.d(TAG, String.format("Disconnected! Code: %d Reason: %s", code, reason)); 1.90 + } 1.91 + 1.92 + @Override 1.93 + public void onError(Exception error) { 1.94 + Log.e(TAG, "Error!", error); 1.95 + } 1.96 +}); 1.97 + 1.98 +client.connect(); 1.99 + 1.100 +// Later… 1.101 +client.emit("Message"); //Message 1.102 +JSONArray arguments = new JSONArray(); 1.103 +arguments.put("first argument"); 1.104 +JSONObject second = new JSONObject(); 1.105 +second.put("dictionary", true); 1.106 +client.emit(second); //JSON Message 1.107 +arguments.put(second); 1.108 +client.emit("hello", arguments); //Event 1.109 +client.disconnect(); 1.110 +``` 1.111 + 1.112 + 1.113 + 1.114 +## TODO 1.115 + 1.116 +* Run [autobahn tests](http://autobahn.ws/testsuite) 1.117 +* Investigate using [naga](http://code.google.com/p/naga/) instead of threads. 1.118 + 1.119 +## License 1.120 + 1.121 +(The MIT License) 1.122 + 1.123 + Copyright (c) 2009-2012 James Coglan 1.124 + Copyright (c) 2012 Eric Butler 1.125 + Copyright (c) 2012 Koushik Dutta 1.126 + 1.127 + Permission is hereby granted, free of charge, to any person obtaining a copy of 1.128 + this software and associated documentation files (the 'Software'), to deal in 1.129 + the Software without restriction, including without limitation the rights to use, 1.130 + copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 1.131 + Software, and to permit persons to whom the Software is furnished to do so, 1.132 + subject to the following conditions: 1.133 + 1.134 + The above copyright notice and this permission notice shall be included in all 1.135 + copies or substantial portions of the Software. 1.136 + 1.137 + THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.138 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 1.139 + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 1.140 + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 1.141 + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1.142 + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 1.143 +