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

Added Android-compatibile support for SNI in direct connections #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ondrap
Copy link

@ondrap ondrap commented Apr 27, 2017

This PR is not meant for direct merging, but rather for a discussion; the problem is that the API for SNI is available in Java8/Android API24 (the 'correct' implementation is in my branch https://github.com/ondrap/nv-websocket-client/tree/android-api24 ). This PR is rather slight refactoring that results in correct behaviour for direct connections on Android systems and possibly plain Java (tested with Java8). SNI in this case doesn't work for proxied connections as there is no API available to do that.

There is a slight drawback though, as there is no way to set connectionTimeout with the createSocket() call, so the system default is used. I'm OK with that for my use, however I am not sure if such a change is appropriate for the library.

// Connect to the server (either a proxy or a WebSocket endpoint); overlay mSocket
// Ignore mConnectionTimeout
mSocket = mSocketFactory.createSocket(mAddress.getHostname(), mAddress.toInetSocketAddress().getPort());
// mSocket.connect(mAddress.toInetSocketAddress(), mConnectionTimeout);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add here mSocket.setSoTimeout(mConnectionTimeout);. It should solve the problem with timeout not being set.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, even better,

mSocket = mSocketFactory.createSocket(); // This will create an unconnected socket
mSocket.setSoTimeout(mConnectionTimeout); // Set timeout
mSocket = mSocketFactory.createSocket(mSocket, mAddress.getHostname(), mAddress.toInetSocketAddress().getPort(), true); // Connect.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

2 participants