Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout in WebSocketClient not used #177

Closed
sfroeth opened this issue May 3, 2013 · 1 comment
Closed

Timeout in WebSocketClient not used #177

sfroeth opened this issue May 3, 2013 · 1 comment

Comments

@sfroeth
Copy link

sfroeth commented May 3, 2013

Hi,

One of the constructors of WebSocketClient takes a value for a timeout, but it is actually never used. The default timeout used by SocketChannel.connect() seems to be something around two minutes if the remote host does not answer. For my use case much shorter timeouts are necessary. I fixed it for me using a thread and calling SocketChannel.close():

// method interruptibleRun():

        /*
         *  Timeout for the SocketChannel using InterruptibleChannel.close()
         *  SocketChannel.connect(...) throws AsynchronousCloseException after calling close()
         */
        if(timeout != 0) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        Thread.sleep(timeout);
                        if(!channel.isConnected()) {
                            channel.close();
                        }
                    } catch (Exception e) {
                        // does not matter
                    }
                }
            }).start();
        }

        channel.connect( new InetSocketAddress( host, port ) );

Regards
Stefan

@Davidiusdadi
Copy link
Collaborator

yeah its true that the timeout is currently not used.
its because its hard to implement it in a clean and performant way. I will
however so something about it within the next weeks.

2013/5/3 sfroeth notifications@github.com

Hi,

One of the constructors of WebSocketClient takes a value for a timeout,
but it is actually never used. The default timeout used by
SocketChannel.connect() seems to be something around two minutes if the
remote host does not answer. For my use case much shorter timeouts are
necessary. I fixed it for me using a thread and calling
SocketChannel.close():

// method interruptibleRun():

    /*
     *  Timeout for the SocketChannel using InterruptibleChannel.close()
     *  SocketChannel.connect(...) throws AsynchronousCloseException after calling close()
     */
    if(timeout != 0) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Thread.sleep(timeout);
                    if(!channel.isConnected()) {
                        channel.close();
                    }
                } catch (Exception e) {
                    // does not matter
                }
            }
        }).start();
    }

    channel.connect( new InetSocketAddress( host, port ) );

Regards
Stefan


Reply to this email directly or view it on GitHubhttps://github.com//issues/177
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants