Simple TCP/IP Socket class for JAVA (and Android)
compile 'me.aflak.libraries:ezsocket:1.0'
<dependency>
<groupId>me.aflak.libraries</groupId>
<artifactId>ezsocket</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
EZSocket socket = new EZSocket("192.168.0.8", 1234, new EZSocket.EZSocketCallback() {
@Override
public void onConnect(EZSocket socket) {
// socket connected
}
@Override
public void onDisconnect(EZSocket socket, String message) {
// socket disconnected
}
@Override
public void onConnectError(final EZSocket socket, String message) {
// error while connecting
}
});
EZSocket socket = new EZSocket(server.accept(), new EZSocket.EZSocketDisconnectCallback() {
@Override
public void onDisconnect(EZSocket socket, String message) {
// socket disconnected
}
});
socket.emit("your_event", "text", 42, "and as many objects as you want");
socket.on("your_event", new EZSocket.Listener() {
@Override
public void onCall(Object... obj) {
String text = (String) obj[0];
Integer n = (Integer) obj[1];
String text = (String) obj[2];
Log.d(msg+" : "+String.valueOf(n));
}
});