X Tutup
Skip to content

Commit 25f33f8

Browse files
committed
intial commit, already working.
0 parents  commit 25f33f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+10877
-0
lines changed

.classpath

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="examples"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
6+
<classpathentry kind="lib" path="lib/json-org.jar"/>
7+
<classpathentry kind="lib" path="lib/WebSocket.jar"/>
8+
<classpathentry kind="output" path="bin"/>
9+
</classpath>

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>io.socket</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Thu Dec 22 15:57:36 CET 2011
2+
eclipse.preferences.version=1
3+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.6
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.source=1.6

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2001 Enno Boland <eb@s01.de>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Socket.IO-Client for Java
2+
3+
io.socket is a simple implementation of [socket.io](http://socket.io) for Java.
4+
5+
It uses [Java-WebSocket](https://github.com/TooTallNate/Java-WebSocket) as transport backend, but it's easy
6+
to write your own transport. See description below.
7+
8+
The API is inspired by [java-socket.io.client](https://github.com/benkay/java-socket.io.client) but as the license
9+
of this project was unclear and it had some nasty bugs, I decided to write io.socket from the scratch.
10+
11+
## How to use
12+
13+
Using io.socket is quite simple. But lets see:
14+
15+
// Initialise a socket:
16+
SocketIO socket = new IOSocket("http://127.0.0.1:3001")
17+
socket.go(new IOCallback() {
18+
@Override
19+
public void onMessage(JSONObject json) {
20+
System.out.println("We received a message: " + json.toString(2));
21+
}
22+
23+
@Override
24+
public void onMessage(String data) {
25+
System.out.println("We received a message:" + data);
26+
}
27+
28+
@Override
29+
public void onError(SocketIOException socketIOException) {
30+
System.out.println("Something went wrong");
31+
}
32+
33+
@Override
34+
public void onDisconnect() {
35+
System.out.println("Disconnected");
36+
}
37+
38+
@Override
39+
public void onConnect() {
40+
System.out.println("Connected");
41+
}
42+
43+
@Override
44+
public void on(String event, JSONObject... args) {
45+
try {
46+
socket.emit("answer", new JSONObject().put("msg", "Hello again Socket.io!"));
47+
} catch (JSONException e) {
48+
e.printStackTrace();
49+
}
50+
}
51+
});
52+
53+
socket.emit("hello", new JSONObject().put("msg", "Hello Socket.io! :D"));
54+
55+
For further informations, read the Javadoc. For end users the interesting parts are io.socket.IOCallback and io.socket.SocketIO.
56+
57+
## What is the architecture?
58+
![Schema](doc/schema.png)
59+
60+
Yea, I know, this is a stub...
61+
62+
## How to implement a transport?
63+
64+
An example can be found in [WebsocketTransport.java](src/io/socket/transports/WebsocketTransport.java)
65+
66+
Create a class implementing the IOTransport interface.
67+
68+
* static IOTransport create(URL url, IOConnection connection)
69+
70+
Called by IOConnector to create a new Instance of the transport. The URL is the one you should connect to. The WebsocketTransport
71+
rewrites the url, so it uses "ws://" instead of "http://". The IOConnection instance should be saved, as the need to call functions
72+
when the status of the transport changes.
73+
74+
* void connect();
75+
76+
Called by IOConnection. Here you should set up the connection.
77+
78+
* void disconnect();
79+
80+
Called by IOConnection. This should shut down the connection. I'm currently not sure if this function is called multiple times.
81+
So make sure, it doesn't crash if it's called more than once.
82+
83+
* void send(String text) throws IOException;
84+
85+
Called by IOConnection. This call request you to send data to the connection endpoint
86+
87+
* boolean canSendBulk();
88+
89+
If you can send more than one message at a time, return true. If not return false.
90+
91+
* void sendBulk(String[] texts) throws IOException;
92+
93+
Basicly the same as send() but for multiple messages at a time. This is only called when canSendBulk returns true.
94+
95+
Ok, now we know when our functions are called. But how do we tell io.socket to process messages we get? IOConnection which the
96+
create() method gets provides methods do to this.
97+
98+
* IOConnection.transportConnect()
99+
100+
Call this method when the connection is established an the socket is ready to send and receive data.
101+
102+
* IOConnection.transportDisconnected()
103+
104+
Call this method when the connection is shot down. IOConnection will care about reconnecting, if it's feasibility.
105+
106+
* IOConnection.transportError(Exception error)
107+
108+
Call this method when the connection is experiencing an error. IOConnection will take care about reconnecting or throwing an
109+
error to the callbacks. Whatever makes more sense ;)
110+
111+
* IOConnection.transportMessage(String message)
112+
113+
This should be called as soon as the transport has received data. IOConnection will take care about parsing the information and
114+
calling the callbacks of the sockets.
115+
116+
So now try to build a transport. :)
117+
118+
## License - the boring stuff...
119+
120+
This library is distributed under MIT Licence.

0 commit comments

Comments
 (0)
X Tutup