diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..31e3d48 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2012 Chris Willingham + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f3e0a42 --- /dev/null +++ b/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'java' +apply plugin: 'eclipse' + +sourceCompatibility = 1.6 +version = '1.0' + +repositories { + mavenCentral() +} + +sourceSets { + example +} + +configurations.exampleCompile.extendsFrom(configurations.compile) + +dependencies { + compile files(projectDir.getAbsolutePath() + '/lib/WebSocket.jar') + compile group: 'commons-collections', name: 'commons-collections', version: '3.2' + compile group: 'org.json', name: 'json', version: '20090211' + testCompile group: 'junit', name: 'junit', version: '4.10' +} + +uploadArchives { + repositories { + flatDir { + dirs 'repos' + } + } +} \ No newline at end of file diff --git a/build.xml b/build.xml deleted file mode 100755 index 6cfa6a3..0000000 --- a/build.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - (fork of) simple java socket.io client. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/json.jar b/lib/json.jar deleted file mode 100644 index cd00cfa..0000000 Binary files a/lib/json.jar and /dev/null differ diff --git a/example/com/clwillingham/socket/io/test/TestClient.java b/src/example/java/com/clwillingham/socket/io/test/TestClient.java similarity index 100% rename from example/com/clwillingham/socket/io/test/TestClient.java rename to src/example/java/com/clwillingham/socket/io/test/TestClient.java diff --git a/src/com/clwillingham/socket/io/IOBeat.java b/src/main/java/com/clwillingham/socket/io/IOBeat.java similarity index 100% rename from src/com/clwillingham/socket/io/IOBeat.java rename to src/main/java/com/clwillingham/socket/io/IOBeat.java diff --git a/src/com/clwillingham/socket/io/IOMessage.java b/src/main/java/com/clwillingham/socket/io/IOMessage.java similarity index 100% rename from src/com/clwillingham/socket/io/IOMessage.java rename to src/main/java/com/clwillingham/socket/io/IOMessage.java diff --git a/src/com/clwillingham/socket/io/IOSocket.java b/src/main/java/com/clwillingham/socket/io/IOSocket.java similarity index 84% rename from src/com/clwillingham/socket/io/IOSocket.java rename to src/main/java/com/clwillingham/socket/io/IOSocket.java index 1dcd176..7972f69 100644 --- a/src/com/clwillingham/socket/io/IOSocket.java +++ b/src/main/java/com/clwillingham/socket/io/IOSocket.java @@ -72,7 +72,7 @@ public void emit(String event, JSONObject... message) throws IOException, Interr } data.put("name", event); data.put("args", args); - IOMessage packet = new IOMessage(IOMessage.EVENT, "", data.toString()); + IOMessage packet = new IOMessage(IOMessage.EVENT, webSocket.getNamespace(), data.toString()); webSocket.sendMessage(packet); } catch (JSONException e) { // TODO Auto-generated catch block @@ -80,8 +80,14 @@ public void emit(String event, JSONObject... message) throws IOException, Interr } } + + public void send(String endpoint, JSONObject message) throws IOException, InterruptedException { + IOMessage packet = new IOMessage(IOMessage.JSONMSG, webSocket.getNamespace(), message.toString()); + webSocket.sendMessage(packet); + } + public void send(String message) throws IOException, InterruptedException { - IOMessage packet = new IOMessage(IOMessage.MESSAGE, "", message); + IOMessage packet = new IOMessage(IOMessage.MESSAGE, webSocket.getNamespace(), message); webSocket.sendMessage(packet); } @@ -89,7 +95,7 @@ public synchronized void disconnect() { if (connected) { try { if (open) { - webSocket.sendMessage(new IOMessage(IOMessage.DISCONNECT, "", "")); + webSocket.sendMessage(new IOMessage(IOMessage.DISCONNECT, webSocket.getNamespace(), "")); } } catch (IOException e) { e.printStackTrace(); diff --git a/src/com/clwillingham/socket/io/IOWebSocket.java b/src/main/java/com/clwillingham/socket/io/IOWebSocket.java similarity index 95% rename from src/com/clwillingham/socket/io/IOWebSocket.java rename to src/main/java/com/clwillingham/socket/io/IOWebSocket.java index eb23056..8f3c15c 100644 --- a/src/com/clwillingham/socket/io/IOWebSocket.java +++ b/src/main/java/com/clwillingham/socket/io/IOWebSocket.java @@ -28,6 +28,7 @@ public IOWebSocket(URI arg0, IOSocket ioSocket, MessageCallback callback) { @Override public void onError(Exception arg0) { // TODO Auto-generated method stub + arg0.printStackTrace(); } diff --git a/src/com/clwillingham/socket/io/Message.java b/src/main/java/com/clwillingham/socket/io/Message.java similarity index 100% rename from src/com/clwillingham/socket/io/Message.java rename to src/main/java/com/clwillingham/socket/io/Message.java diff --git a/src/com/clwillingham/socket/io/MessageCallback.java b/src/main/java/com/clwillingham/socket/io/MessageCallback.java similarity index 100% rename from src/com/clwillingham/socket/io/MessageCallback.java rename to src/main/java/com/clwillingham/socket/io/MessageCallback.java