Socket.IO Client Implementation in Java

Overview

Flattr this git repo

Socket.IO-Client for Java

socket.io-java-client is an easy to use implementation of socket.io for Java.

It uses Weberknecht as transport backend, but it's easy to write your own transport. See description below. An XHR-Transport is included, too. But it's not functional in its current state.

The API is inspired by java-socket.io.client.

Features:

  • transparent reconnecting - The API cares about re-establishing the connection to the server when the transport is interrupted.
  • easy to use API - implement an interface, instantiate a class - you're done.
  • output buffer - send data while the transport is still connecting. No problem, socket.io-java-client handles that.
  • meaningful exceptions - If something goes wrong, SocketIO tries to throw meaningful exceptions with hints for fixing.

Status: Connecting with Websocket is production ready. XHR is in beta.

How to use

Using socket.io-java-client is quite simple. But lets see:

Checkout and compile the project:

git clone git://github.com/Gottox/socket.io-java-client.git
cd socket.io-java-client
ant jar
mv jar/socketio.jar /path/to/your/libs/project

If you're using ant, change your build.xml to include socketio.jar. If you're eclipse, add the jar to your project buildpath.

Afterwards, you'll be able to use this library:

		SocketIO socket = new SocketIO("http://127.0.0.1:3001/");
		socket.connect(new IOCallback() {
			@Override
			public void onMessage(JSONObject json, IOAcknowledge ack) {
				try {
					System.out.println("Server said:" + json.toString(2));
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onMessage(String data, IOAcknowledge ack) {
				System.out.println("Server said: " + data);
			}

			@Override
			public void onError(SocketIOException socketIOException) {
				System.out.println("an Error occured");
				socketIOException.printStackTrace();
			}

			@Override
			public void onDisconnect() {
				System.out.println("Connection terminated.");
			}

			@Override
			public void onConnect() {
				System.out.println("Connection established");
			}

			@Override
			public void on(String event, IOAcknowledge ack, Object... args) {
				System.out.println("Server triggered event '" + event + "'");
			}
		});
		
		// This line is cached until the connection is establisched.
		socket.send("Hello Server!");

For further informations, read the Javadoc.

Checkout

  • with git

     git clone git://github.com/Gottox/socket.io-java-client.git
    
  • with mercurial

     hg clone https://bitbucket.org/Gottox/socket.io-java-client 
    

Both repositories are synchronized and up to date.

Building

to build a jar-file:

cd $PATH_TO_SOCKETIO_JAVA
ant jar
ls jar/socketio.jar

You'll find the socket.io-jar in jar/socketio.jar

Bugs

Please report any bugs feature requests to the Github issue tracker

Frameworks

This Library was designed with portability in mind.

  • Android is fully supported.
  • JRE is fully supported.
  • GWT does not work at the moment, but a port would be possible.
  • Java ME does not work at the moment, but a port would be possible.
  • ... is there anything else out there?

Testing

There comes a JUnit test suite with socket.io-java-client. Currently it's tested with Eclipse.

You need node installed in PATH.

  • open the project with eclipse
  • open tests/io.socket/AllTests.java
  • run it as JUnit4 test.

TODO

  • Socket.io needs more unit-tests.
  • XhrTransport needs to pass all tests.
  • If websockets are failing (due to proxy servers e.g.), use XHR automaticly instead.

License - the boring stuff...

This library is distributed under MIT Licence.

Sounds so interesting...

You'll find further documentation at the Socket.io-java-client Github Wiki

Comments
  • Connecting with query parameters

    Connecting with query parameters

    Hi,

    I had problems using your api when the url I needed to connect to had ?key=val

    I am currently just trying to get a project working in my spare time so I have take your source into my project and fixed it. But my fix is pretty crude and might not working all cases.

    The crux of the fix is in the handshake() method in IOConnection, to do something like this:

            URL origin = getOrigin();
            if (IOConnection.this.url.getQuery() != null && IOConnection.this.url.getQuery() != "") {
                url = new URL(origin.toString() + SOCKET_IO_1 + "?" + IOConnection.this.url.getQuery());
            } else {
                url = new URL(origin.toString() + SOCKET_IO_1);
            }
    

    When you set the url field in IOConnection you only set the origin (there might be a good reason for this...!). Instead I changed it to set the full URL and then wrote a getOrigin method which I called in the right places.

    private URL getOrigin() throws MalformedURLException {
        return new URL(IOConnection.this.url.getProtocol() + "://" + IOConnection.this.url.getHost());
    }
    

    This seems to work, apologies if I have misunderstood your api, thanks for writing it though :)

    Rich

    opened by peenuty 8
  • socket blocks on disconnect.

    socket blocks on disconnect.

    First of all thanks for this library.

    I am trying to use it in one of my android app. I am having some issue with disconnection.

    I am able to connect, emit and receive data, and sometimes successfully disconnect. But most time, the execution blocks on disconnect method call

    mLiveSockIO.disconnect();
    

    and onDisconnect() or onError() not getting called in this case, and app freezes. I debugged with breakpoint and I can confirm that execution blocks on above given line.

    public void setupLiveSocketIO(){
        try {
            mLiveSockIO =   new SocketIO("http://" + mStreamHost + ":" +mStreamPort+"/");
        } catch (MalformedURLException e) {
            return;
        }
    
        mLiveSockIO.connect(new IOCallback() {
            @Override
            public void onMessage(JSONObject arg0, IOAcknowledge arg1) {
                AppConstants.log(mHostName + " On Message json " + arg0.toString()); 
            }
    
            @Override
            public void onMessage(String arg0, IOAcknowledge arg1) {
                AppConstants.log(mHostName + " On Message String " + arg0.toString());
            }
    
            @Override
            public void onError(SocketIOException arg0) {
                AppConstants.log("live sock io onError");
                arg0.printStackTrace();
            }
    
            @Override
            public void onDisconnect() {
                AppConstants.log(mHostName + "live sock io onDisconnect");
            }
    
            @Override
            public void onConnect() {
                AppConstants.log("live sock io on Connect");
                sendUpdatedLiveRequest("");
            }
    
            @Override
            public void on(final String arg0, IOAcknowledge arg1, Object... arg2) {
                for(int i = 0 ;i < arg2.length ;i++){
                    final String response       =   arg2[i].toString();
                    Thread thread               =   new Thread(new Runnable() {
                        @Override
                        public void run() {
                            JSONParser  parse   =   new JSONParser(response, mContext,arg0);
                            String result       =   parse.startParsing();
                            postNotificationString(AppConstants.PARSE_SUCCESSFULL, result, arg0);
                        }
                    });
                    thread.start();
                }
            }
        });
    }
    

    And my disconnect call

    public void disconnect(){
        AppConstants.log(" disconnect called");
        if(mLiveSockIO != null && mLiveSockIO.isConnected()){
            mIsDisconnected                 =   true;
            mLiveSockIO.disconnect();
        }
        AppConstants.log(" socketio disconnected");
        clear();
        AppConstants.log(" dictionaries clear");
    }
    

    Well I am getting log

    07-30 14:19:23.448: E/DEBUG(17969): disconnect called

    and thats all.. Lines below

    mLiveSockIO.disconnect()
    

    never get executed. I am not getting any exception.. I am not sure what is causing this behaviour..

    1. I am connecting and disconnecting in the same thread (UI thread in this case). I somewhere read that is necessary
    2. There might be chance that, when the time disconnect gets called, there are data to be received on the socket. In my case , once disconnect is called I dont want to receive any pending data. But I couldn't find anyway to flush out the data before disconnecting.
    3. I am not using any synchronisation or lock mechanisms, that might cause such a block. There are no exception either.
    4. The server part is working fine.. A client code in iphone is connecting to the same server and getting disconnected successfully.
    opened by ghost 7
  • 'ant jar' doesn't build

    'ant jar' doesn't build

    Following the instruction on README, doing 'ant jar' I'm currently getting the following:

    BUILD FAILED
    Target "jar" does not exist in the project "socket.io-java-client". 
    
    opened by foodpoison 5
  • Intermittent ConnectThread Exception

    Intermittent ConnectThread Exception

    I intermittently encounter the following fatal exception after I connect to my server. I've attached the crash logs to help identify the issue. Is there something I'm doing incorrect here?

    05-21 16:23:10.367: I/System.out(7412): Connection established 05-21 16:23:10.375: W/dalvikvm(7412): threadid=17: thread exiting with uncaught exception (group=0x4001e560) 05-21 16:23:10.375: E/AndroidRuntime(7412): FATAL EXCEPTION: ConnectThread 05-21 16:23:10.375: E/AndroidRuntime(7412): java.lang.IllegalStateException: TimerTask is canceled 05-21 16:23:10.375: E/AndroidRuntime(7412): at java.util.Timer.scheduleImpl(Timer.java:578) 05-21 16:23:10.375: E/AndroidRuntime(7412): at java.util.Timer.schedule(Timer.java:461) 05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection.resetTimeout(IOConnection.java:480) 05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection.transportConnected(IOConnection.java:515) 05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.WebsocketTransport.onOpen(WebsocketTransport.java:123) 05-21 16:23:10.375: E/AndroidRuntime(7412): at de.roderick.weberknecht.WebSocketConnection.connect(WebSocketConnection.java:139) 05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.WebsocketTransport.connect(WebsocketTransport.java:129) 05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection.connectTransport(IOConnection.java:332) 05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection.access$300(IOConnection.java:38) 05-21 16:23:10.375: E/AndroidRuntime(7412): at io.socket.IOConnection$ConnectThread.run(IOConnection.java:201)

    opened by dbzhang 5
  • Error while handshaking - java.io.FileNotFoundException

    Error while handshaking - java.io.FileNotFoundException

    I'm using Socket.io v1.0.4 on the server, and the current version fo this client.

    06-10 12:56:04.799: W/System.err(31384): io.socket.SocketIOException: Error while handshaking 06-10 12:56:04.819: W/System.err(31384): at io.socket.IOConnection.handshake(IOConnection.java:322) 06-10 12:56:04.819: W/System.err(31384): at io.socket.IOConnection.access$600(IOConnection.java:39) 06-10 12:56:04.829: W/System.err(31384): at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199) 06-10 12:56:04.829: W/System.err(31384): Caused by: java.io.FileNotFoundException: http://24.229.26.132:3000/socket.io/1/ 06-10 12:56:04.829: W/System.err(31384): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186) 06-10 12:56:04.829: W/System.err(31384): at io.socket.IOConnection.handshake(IOConnection.java:313)

    opened by asuej28 4
  • Missing org.java_websocket.client dependency

    Missing org.java_websocket.client dependency

    (after 594a0e5842cc9cc146b63aa0b32796c714b5a314, which switched from Weberknecht to Java-Websockets)

    (The workaround is to build @ b01ff2c7cbfdd55962058e44bbd70285b2989c78 (previous commit) or add the dependency.)

    drhop@hexxer:~/dev/otartc/third_party/socket.io-java-client$ ant jar Buildfile: /home/drhop/dev/otartc/third_party/socket.io-java-client/build.xml

    init: [mkdir] Created dir: /home/drhop/dev/otartc/third_party/socket.io-java-client/bin

    build-project: [echo] socket.io-java-client: /home/drhop/dev/otartc/third_party/socket.io-java-client/build.xml [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/build.xml:40: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds [javac] Compiling 9 source files to /home/drhop/dev/otartc/third_party/socket.io-java-client/bin [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:11: package org.java_websocket.client does not exist [javac] import org.java_websocket.client.DefaultSSLWebSocketClientFactory; [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:12: package org.java_websocket.client does not exist [javac] import org.java_websocket.client.WebSocketClient; [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:13: package org.java_websocket.handshake does not exist [javac] import org.java_websocket.handshake.ServerHandshake; [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:15: cannot find symbol [javac] symbol: class WebSocketClient [javac] class WebsocketTransport extends WebSocketClient implements IOTransport { [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:86: cannot find symbol [javac] symbol : class ServerHandshake [javac] location: class io.socket.WebsocketTransport [javac] public void onOpen(ServerHandshake handshakedata) { [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:15: io.socket.WebsocketTransport is not abstract and does not override abstract method send(java.lang.String) in io.socket.IOTransport [javac] class WebsocketTransport extends WebSocketClient implements IOTransport { [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:25: incompatible types [javac] found : io.socket.WebsocketTransport [javac] required: io.socket.IOTransport [javac] return new WebsocketTransport(uri, connection); [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:33: cannot find symbol [javac] symbol : class DefaultSSLWebSocketClientFactory [javac] location: class io.socket.WebsocketTransport [javac] this.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(context)); [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:43: cannot find symbol [javac] symbol : method close() [javac] location: class io.socket.WebsocketTransport [javac] this.close(); [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:73: method does not override or implement a method from a supertype [javac] @Override [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:79: method does not override or implement a method from a supertype [javac] @Override [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:85: method does not override or implement a method from a supertype [javac] @Override [javac] ^ [javac] /home/drhop/dev/otartc/third_party/socket.io-java-client/src/io/socket/WebsocketTransport.java:96: method does not override or implement a method from a supertype [javac] @Override [javac] ^ [javac] 13 errors

    opened by drhops 4
  • Deadlock involving IOConnection instance and outputBuffer

    Deadlock involving IOConnection instance and outputBuffer

    I'm running into deadlocks every now and then. Taking a thread dump revealed the objects involved. A socket.io-java-client thread called "ConnectThread" calls IOConnection.connectTransport, which locks, in this order

    1. this (as connectTransport() is synchronized)
    2. outputBuffer (explicitly in IOConnection.transportConnected()

    Now my own thread calls SocketIO.emit, which locks, in this order

    1. outputBuffer (explicitly in IOConnection.sendPlain())
    2. this (by calling getState() which is synchronized)

    Still not having had the time to go read the code, the quick fix for me was to make IOConnection.sendPlain(String) synchronized, which reverses the order that sendPlain() takes those 2 locks, thus averting the deadlock.

    It works great for me so far (I'm creating 5000 client instances in a single JVM in a matter of seconds now), but there might be better ways to fix it for those who know the code. In any event, here are the relevant bits from the thread dump (line numbers seem to be off by 1, and maybe by more due to my local changes, so it's probably easier to just use the method names).

    Found one Java-level deadlock:

    "Thread-5789": waiting to lock monitor 0x00002aab9be10e48 (object 0x0000000785ebcde0, a java.util.concurrent.ConcurrentLinkedQueue), which is held by "pool-1-thread-16" "pool-1-thread-16": waiting to lock monitor 0x00002aab9be07670 (object 0x0000000785ebcba0, a io.socket.IOConnection), which is held by "ConnectThread" "ConnectThread": waiting to lock monitor 0x00002aab9be10e48 (object 0x0000000785ebcde0, a java.util.concurrent.ConcurrentLinkedQueue), which is held by "pool-1-thread-16"

    Java stack information for the threads listed above:

    "Thread-5789": at io.socket.IOConnection.sendPlain(IOConnection.java:449) - waiting to lock <0x0000000785ebcde0> (a java.util.concurrent.ConcurrentLinkedQueue) at io.socket.IOConnection.transportMessage(IOConnection.java:645) at io.socket.WebsocketTransport.onMessage(WebsocketTransport.java:117) at de.roderick.weberknecht.WebSocketReceiver.run(WebSocketReceiver.java:57) "pool-1-thread-16": at io.socket.IOConnection.getState(IOConnection.java:849) - waiting to lock <0x0000000785ebcba0> (a io.socket.IOConnection) at io.socket.IOConnection.sendPlain(IOConnection.java:450) - locked <0x0000000785ebcde0> (a java.util.concurrent.ConcurrentLinkedQueue) at io.socket.IOConnection.emit(IOConnection.java:826) at io.socket.SocketIO.emit(SocketIO.java:236)
    at benchmark.Benchmarker.RegisterInner(Benchmarker.java:215) at benchmark.Benchmarker.access$100(Benchmarker.java:48) at benchmark.Benchmarker$3.run(Benchmarker.java:204) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) "ConnectThread": at io.socket.IOConnection.transportConnected(IOConnection.java:518) - waiting to lock <0x0000000785ebcde0> (a java.util.concurrent.ConcurrentLinkedQueue) at io.socket.WebsocketTransport.onOpen(WebsocketTransport.java:123) at de.roderick.weberknecht.WebSocketConnection.connect(WebSocketConnection.java:139) at io.socket.WebsocketTransport.connect(WebsocketTransport.java:129) at io.socket.IOConnection.connectTransport(IOConnection.java:333) - locked <0x0000000785ebcba0> (a io.socket.IOConnection) at io.socket.IOConnection.access$200(IOConnection.java:38) at io.socket.IOConnection$ConnectThread.run(IOConnection.java:200)

    Found 1 deadlock.

    opened by EugenDueck 4
  • onMessage does not called

    onMessage does not called

    When message recieve, IOCallback on(java.lang.String event, IOAcknowledge ack, java.lang.Object... args) is called.

    But neither onMessage(java.lang.String data, IOAcknowledge ack)
    nor onMessage(org.json.JSONObject json, IOAcknowledge ack) being called.

    PLEASE HELP !

    THX

    opened by mike-aungsan 3
  • server reconnection issue

    server reconnection issue

    Hi guys, I ran into an issue with the server reconnection. When the server goes down and then comes up again I get this exception on the client:

    I/io.socket(  333): < 7:::1+0
    I/System.out(  333): an Error occured
    W/System.err(  333): io.socket.SocketIOException: 1+0
    W/System.err(  333):    at io.socket.IOConnection.transportMessage(IOConnection.java:736)
    W/System.err(  333):    at io.socket.WebsocketTransport.onMessage(WebsocketTransport.java:82)
    W/System.err(  333):    at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:361)
    W/System.err(  333):    at org.java_websocket.WebSocketImpl.deliverMessage(WebSocketImpl.java:565)
    W/System.err(  333):    at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:331)
    W/System.err(  333):    at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:152)
    W/System.err(  333):    at org.java_websocket.client.WebSocketClient.interruptableRun(WebSocketClient.java:247)
    W/System.err(  333):    at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:193)
    W/System.err(  333):    at java.lang.Thread.run(Thread.java:1019)
    I/io.socket(  333): Cleanup
    
    
    opened by mkuklis 3
  • Any way to set some custom headers?

    Any way to set some custom headers?

    It would be really useful for me to be able to pass in some custom headers during the connection. This is something that could be read on the authorization event on socket io? Any way to do this?

    opened by cendrizzi 3
  • Timeout not working correctly

    Timeout not working correctly

    Why do you call cleanup() here: https://github.com/Gottox/socket.io-java-client/blob/master/src/io/socket/IOConnection.java#L151 ?

    Calling error() after cleanup() is useless, isn't it?

    I guess there should be called only error(...) method.

    opened by ivankosdy 3
  • Null pointer exception when emmiting to socket

    Null pointer exception when emmiting to socket

    This code throws an NPE for some reason , although I dont use any null values

    ` import java.awt.AWTException; import java.awt.HeadlessException; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.util.Base64;

    import javax.imageio.ImageIO;

    import org.json.JSONException; import org.json.JSONObject;

    import io.socket.*; import io.socket.IOCallback; public class Main{ //implements IOCallback {

    /*public static byte[]  snap(String name) throws HeadlessException, AWTException, IOException{
    	BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
    	ImageIO.write(image, "jpg", new File(name));
    	ByteArrayOutputStream baos = new ByteArrayOutputStream();
    }*/
    public static String snap() throws IOException  {
    
        Rectangle screen = new 
        Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        BufferedImage screenCapture = null;
        String base64Encoded = "";
    
        try {
    
            screenCapture = new Robot().createScreenCapture(screen);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(screenCapture, "jpg", baos);
            baos.flush();
            byte[] encodedBytes = Base64.getEncoder().encode(baos.toByteArray());
            base64Encoded = new String(encodedBytes);
            baos.close();
    
        } catch (AWTException e) {
            e.getMessage();
        }
    
        return base64Encoded;
    }
    public static int BasicExample(String img) throws IOException {
    	SocketIO socket = new SocketIO("http://127.0.0.1:5000/");
    	
    
    	// Sends a string to the server.
    	
    
    	
    
    	// Emits an event to the server.
    	socket.emit(img);
    	return 3;
    }
    public static void main(String[] args) throws IOException, HeadlessException, AWTException {
    	for (int i = 0; i<10; i++){
    		
    		//String name = "./ScreenShot" + Integer.toString(i) + ".jpg";
    		
    		//System.out.println(snap());
    		 int w = BasicExample(snap());
    	}
    	//SocketIO socket = new SocketIO("http://127.0.0.1:5000/");
    	
    	
    }
    

    }`

    opened by Mcilie 0
  • socket.io FileNotFoundException

    socket.io FileNotFoundException

    Hi I try to connect node.js .I wrote some code

     try {
            SocketIO socket = new SocketIO("http://54e1755a.ngrok.io/");
            socket.connect(new IOCallback() {
                @Override
                public void on(String event, IOAcknowledge ack, Object... args) {
                    if ("echo back".equals(event) && args.length > 0) {
                        Log.d("SocketIO", "" + args[0]);
                    }
                }
    
                @Override
                public void onMessage(JSONObject json, IOAcknowledge ack) {
                    Log.e("onDisconnect","onDisconnect");
                }
    
                @Override
                public void onMessage(String data, IOAcknowledge ack) {
                    Log.e("onDisconnect","onDisconnect");
                }
    
                @Override
                public void onError(SocketIOException socketIOException) {
                    socketIOException.printStackTrace();
                }
    
                @Override
                public void onDisconnect() {
                    Log.e("onDisconnect","onDisconnect");
    
                }
    
                @Override
                public void onConnect() {
                    Log.e("onConnect","onConnect");
                }
            });
            socket.emit("echo", "hello");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    

    When i run my app i have FileNotFoundException . Error message is : Caused by: java.io.FileNotFoundException: http://54e1755a.ngrok.io/socket.io/1/ as you can see socket.io added automaticly socket.io/1/ in url ngrok url working correct.I tested it in brower

    opened by Bekakk 4
  • Windows 10 not working

    Windows 10 not working

    io.socket.SocketIOException: Error while handshaking at io.socket.IOConnection.handshake(IOConnection.java:322) at io.socket.IOConnection.access$600(IOConnection.java:39) at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199) Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:152) at java.net.SocketInputStream.read(SocketInputStream.java:122) at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) at java.io.BufferedInputStream.read1(BufferedInputStream.java:275) at java.io.BufferedInputStream.read(BufferedInputStream.java:334) at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323) at io.socket.IOConnection.handshake(IOConnection.java:313) ... 2 more Jun 22, 2016 12:24:32 PM io.socket.IOConnection cleanup INFORMACIÓN: Cleanup

    Server starting without error, but client can`t connect

    Any comment ?

    opened by jjsainzc 0
  • Configure path to the resource

    Configure path to the resource

    Hi! I was using the library when I realized that I can't configure the path/resource to the socket.io. Now the variable SOCKET_IO_1 is fixed to /socket/1, but in some environments and projects it could be possible that the path to the socketio is something like /xxxx/socket/1. So I propose to add the option to configure it, I can make the PR

    opened by marclr 0
  • Issue in running the project

    Issue in running the project

    Hi I just downloaded this and imported it into eclipse, but when I try to run the basicExample.java I get,

    Error while handshaking Server returned HTTP response code: 400 for URL: http://localhost:3000/socket.io/1/

    Any suggestion?

    1. Not behind proxy.
    2. Node server is running on same port 3000(changed in both .js an .java)
    opened by ghost 2
Owner
Enno Boland
Enno Boland
A Java library that implements a ByteChannel interface over SSLEngine, enabling easy-to-use (socket-like) TLS for Java applications.

TLS Channel TLS Channel is a library that implements a ByteChannel interface over a TLS (Transport Layer Security) connection. It delegates all crypto

Mariano Barrios 149 Dec 31, 2022
Socket.IO server implemented on Java. Realtime java framework

Netty-socketio Overview This project is an open-source Java implementation of Socket.IO server. Based on Netty server framework. Checkout Demo project

Nikita Koksharov 6k Dec 30, 2022
jRT measures the response time of a java application to socket-based requests

jRT Version: 0.0.1 jRT is a instrumentation tool that logs and records networking I/O operations "response times" (applicaion response time if be corr

null 45 May 19, 2022
An netty based asynchronous socket library for benchion java applications

Benchion Sockets Library An netty based asynchronous socket library for benchion java applications ?? Documents ?? Report Bug · Request Feature Conten

Fitchle 3 Dec 25, 2022
This is library that look like Scarlet Wrapper Socket.io

This is library that look like Scarlet Wrapper Socket.io

Adkhambek 8 Jan 2, 2023
A simple Socket program with GUI.

Socket A simple Socket program with GUI (by using swing). Suggest to open the folder 'Socket'(TCP) or 'SocketUDP' with IDEA There're 2 methods to run

Lu Yang 2 Sep 21, 2022
A barebones WebSocket client and server implementation written in 100% Java.

Java WebSockets This repository contains a barebones WebSocket server and client implementation written in 100% Java. The underlying classes are imple

Nathan Rajlich 9.5k Dec 30, 2022
The Java gRPC implementation. HTTP/2 based RPC

gRPC-Java - An RPC library and framework gRPC-Java works with JDK 7. gRPC-Java clients are supported on Android API levels 16 and up (Jelly Bean and l

grpc 10.2k Jan 1, 2023
Nifty is an implementation of Thrift clients and servers on Netty

his project is archived and no longer maintained. At the time of archiving, open issues and pull requests were clo

Meta Archive 902 Sep 9, 2022
Apache Thrift is a lightweight, language-independent software stack for point-to-point RPC implementation

Apache Thrift Introduction Thrift is a lightweight, language-independent software stack for point-to-point RPC implementation. Thrift provides clean a

The Apache Software Foundation 9.5k Jan 4, 2023
TCP/UDP client/server library for Java, based on Kryo

KryoNet can be downloaded on the releases page. Please use the KryoNet discussion group for support. Overview KryoNet is a Java library that provides

Esoteric Software 1.7k Jan 2, 2023
Proteus Java Client

Netifi Proteus Java This project has been moved to https://github.com/netifi/netifi-java Build from Source Run the following Gradle command to build t

netifi-proteus 42 Nov 20, 2020
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Dec 31, 2022
Telegram API Client and Telegram BOT API Library and Framework in Pure java.

Javagram Telegram API Client and Telegram Bot API library and framework in pure Java. Hello Telegram You can use Javagram for both Telegram API Client

Java For Everything 3 Oct 17, 2021
A small java project consisting of Client and Server, that communicate via TCP/UDP protocols.

Ninja Battle A small java project consisting of Client and Server, that communicate via TCP/UDP protocols. Client The client is equipped with a menu i

Steliyan Dobrev 2 Jan 14, 2022
FileServer - A multithreaded client-server program that uses Java Sockets to establish TCP/IP connection

A multithreaded client-server program that uses Java Sockets to establish TCP/IP connection. The server allows multiple clients to upload, retrieve and delete files on/from the server.

Lokesh Bisht 3 Nov 13, 2022
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

Square 43.4k Jan 9, 2023
BAIN Social is a Fully Decentralized Server/client system that utilizes Concepts pioneered by I2P, ToR, and PGP to create a system which bypasses singular hosts for data while keeping that data secure.

SYNOPSIS ---------------------------------------------------------------------------------------------------- Welcome to B.A.I.N - Barren's A.I. Natio

Barren A.I. Wolfsbane 14 Jan 11, 2022
IoT Platform, Device management, data collection, processing and visualization, multi protocol, rule engine, netty mqtt client

GIoT GIoT: GIoT是一个开源的IoT平台,支持设备管理、物模型,产品、设备管理、规则引擎、多种存储、多sink、多协议(http、mqtt、tcp,自定义协议)、多租户管理等等,提供插件化开发 Documentation Quick Start Module -> giot-starte

gerry 34 Sep 13, 2022