Comments (17)
Could you tell me the URL? I'll try to access it.
from nv-websocket-client.
You see the error message "Failed to get the input stream of the raw socket" when getInputStream()
of java.net.Socket
failed. See the implementation of openInputStream(Socket)
in WebSocket.java
.
The WebSocketException
instance you receive in onError
method contains the IOException
instance that getInputStream()
threw. Please check what the exception is saying. LIke this:
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception
{
// Print the stack trace of the IOException.
cause.getCause().printStackTrace();
}
from nv-websocket-client.
Hi TakahikoKawasaki,I also encountered this problem and this is my code:
public void initWs() throws IOException, WebSocketException,
URISyntaxException, NoSuchAlgorithmException {
String token = "0EE86165533E49841A063472B8639223|8baaf6b1385145545c4ec4c4c151e0aa|1444295714";
token = URLEncoder.encode(token, "UTF-8");
String exampleUri;
exampleUri = "wss://yggdrasil.bz-inc.com:11506/im?token=" + token;
// exampleUri = "wss://echo.websocket.org";
// exampleUri = "ws://echo.websocket.org";
WebSocketFactory webSocketFactory = new WebSocketFactory();
webSocketFactory
.setSSLContext(
SSLContext.getInstance("Default"))
.setSSLSocketFactory(
(SSLSocketFactory) SSLSocketFactory.getDefault());
ws = webSocketFactory
.setConnectionTimeout(TIMEOUT)
.createSocket(exampleUri)
.setPingInterval(20 * 1000)
.addListener(webSocketAdapter);
ws.connect();
}
from nv-websocket-client.
Please read the JavaDoc of WebSocketFactory.createSocket(URI) for details about SSL configuration. Also, see the discussion in #6. In short, if you call setSSLContext()
, calling setSSLSocketFactory()
has no meaning. Moreover, if you want to use the default settings, you don't have to call setSSL*()
functions at all.
Please check whether SSLContext.getInstance("Default")
returns a valid SSLContext
instance. I'm not sure SSLContext.getInstance(String)
accepts "Default"
as a valid value.
from nv-websocket-client.
I released a new version 1.11. Please use it to see what an additional error message says after "Failed to get the input stream of the raw socket".
The following is the CHANGES made in version 1.11.
1.11 (2015-10-12)
- Changed some error messages of
WebSocketException
.
(Appendedcause.getMessage()
in cases where a cause is available.)
from nv-websocket-client.
That is ok, thank you so much!
from nv-websocket-client.
yeah , now I can connect our server by version 1.11. but some urls contain '|' can`t be created URI directly,so I changed your code. My connecting code:
from nv-websocket-client.
Oh, sorry. It's my bug. I fixed the bug and released a new version 1.12. Please try the new version.
1.12 (2015-10-12)
- Fixed a bug in
WebSocketFactory
.getRawPath()
andgetRawQuery()
should be used instead ofgetPath()
andgetQuery()
.
from nv-websocket-client.
That is right! It is so easy for me to connect our server .We`re using your library in our IM system and it seems very good.Of course ,If there are some other troubles bother me, I will come back to ask for your help immediately.
from nv-websocket-client.
I am also getting similar error. Below is error, Can you please help
01-02 02:46:50.420 3698-4278/com.neovisionaries.ws.client W/System.err: com.neovisionaries.ws.client.WebSocketException: Failed to get the input stream of the raw socket: Connection closed by peer
01-02 02:46:50.450 3698-4278/com.neovisionaries.ws.client W/System.err: at com.neovisionaries.ws.client.WebSocket.openInputStream(WebSocket.java:2831)
01-02 02:46:50.478 3698-4278/com.neovisionaries.ws.client W/System.err: at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:2789)
01-02 02:46:50.504 3698-4278/com.neovisionaries.ws.client W/System.err: at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:1867)
01-02 02:46:50.531 3698-4278/com.neovisionaries.ws.client W/System.err: at com.neovisionaries.ws.client.EchoClient.connect(EchoClient.java:118)
01-02 02:46:50.559 3698-4278/com.neovisionaries.ws.client W/System.err: at com.neovisionaries.ws.client.EchoClient.connectWebSocket(EchoClient.java:66)
01-02 02:46:50.589 3698-4278/com.neovisionaries.ws.client W/System.err: at com.neovisionaries.ws.client.MainActivity$PerformTask.doInBackground(MainActivity.java:35)
01-02 02:46:50.620 3698-4278/com.neovisionaries.ws.client W/System.err: at com.neovisionaries.ws.client.MainActivity$PerformTask.doInBackground(MainActivity.java:30)
01-02 02:46:50.645 3698-4278/com.neovisionaries.ws.client W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
01-02 02:46:50.672 3698-4278/com.neovisionaries.ws.client W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-02 02:46:50.697 3698-4278/com.neovisionaries.ws.client W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
01-02 02:46:50.727 3698-4278/com.neovisionaries.ws.client W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-02 02:46:50.759 3698-4278/com.neovisionaries.ws.client W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-02 02:46:50.783 3698-4278/com.neovisionaries.ws.client W/System.err: at java.lang.Thread.run(Thread.java:818)
01-02 02:46:50.810 3698-4278/com.neovisionaries.ws.client W/System.err: Caused by: javax.net.ssl.SSLHandshakeException: Connection closed by peer
01-02 02:46:50.926 3698-4278/com.neovisionaries.ws.client W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
01-02 02:46:50.957 3698-4278/com.neovisionaries.ws.client W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
01-02 02:46:50.988 3698-4278/com.neovisionaries.ws.client W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.waitForHandshake(OpenSSLSocketImpl.java:598)
01-02 02:46:51.019 3698-4278/com.neovisionaries.ws.client W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:560)
01-02 02:46:51.047 3698-4278/com.neovisionaries.ws.client W/System.err: at com.neovisionaries.ws.client.WebSocket.openInputStream(WebSocket.java:2824)
01-02 02:46:51.058 3698-4278/com.neovisionaries.ws.client W/System.err: ... 12 more
Below is my code. Please let me know if something is wrong
private static WebSocket connect() throws Exception {
// Create a custom SSL context.
SSLContext context = NaiveSSLContext.getInstance("TLS");
WebSocket socket = new WebSocketFactory()
.setSSLContext(context) // Set the custom SSL context.
.setConnectionTimeout(TIMEOUT)
.createSocket(SERVER)
.addProtocol("BB-GW-01")
.addListener(new WebSocketAdapter() {
// A text message arrived from the server.
public void onTextMessage(WebSocket websocket, String message) {
//System.out.println(message);
Log.d("EchoClient", message);
}
})
.addExtension(WebSocketExtension.PERMESSAGE_DEFLATE);
try {
return socket.connect();
} catch (OpeningHandshakeException e) {
// Status line.
StatusLine sl = e.getStatusLine();
System.out.println("=== Status Line ===");
System.out.format("HTTP Version = %s\n", sl.getHttpVersion());
System.out.format("Status Code = %d\n", sl.getStatusCode());
System.out.format("Reason Phrase = %s\n", sl.getReasonPhrase());
// HTTP headers.
Map<String, List<String>> headers = e.getHeaders();
System.out.println("=== HTTP Headers ===");
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
// Header name.
String name = entry.getKey();
// Values of the header.
List<String> values = entry.getValue();
if (values == null || values.size() == 0) {
// Print the name only.
System.out.println(name);
continue;
}
for (String value : values) {
// Print the name and the value.
System.out.format("%s: %s\n", name, value);
}
}
return null;
}
}
from nv-websocket-client.
The stack trace says "Connection closed by peer". You may be able to find a hint in the log messages on the server side.
In addition, what is BB-GW-01
protocol? nv-websocket-client does not support the protocol.
from nv-websocket-client.
Thanks for your response.
BB-GW-01 is subprotocol in websocket.
I am attaching screen shot of wireshark if you can make out what can be problem . 192.168.50.104 is my mobile IP and 192.168.50.1 is Server IP. Server is written using libwebsocket C library and we are able to connect using iPhone to the same server using wss.
I am able to connect on ws but not on wss using nvwebsocket client library
from nv-websocket-client.
Also sometime I get this in wireshark but both time I get same stack trace
from nv-websocket-client.
I'm afraid that the root cause is in the implementation of TLS. What if you give "TLSv1.2"
to NaiveSSLContext.getInstance(String)
instead of "TLS"
?
FYI: javax.net.ssl.SSLContext.getInstance(String)
from nv-websocket-client.
It make no difference whether i give TLSv1.2 or TLS. In my scenario I am connecting to an embedded Linux based device which provide webscoket server. It had custom certificate hence I am ignoring them using NavieContext. Now there are two scenario
- When Embedded device and Android both are in corporate network , I am able to connect to websocket server
- When Android directly connect to embedded device on device's wifi access point then it give SSL_handshake error.
I am attaching snapshot of wireshark log for both cases. In case you want actual wireshark to make nay comment then let me know.
from nv-websocket-client.
Hi,
In continuation to my earlier issue of not albe to connect to after some more research I had found out the reason. In SSL connection android SDK an unnecessary DNS lookup which causes delay. Please see link http://stackoverflow.com/questions/4737019/tls-connection-using-sslsocket-is-slow-in-android-os
In my case it was taking around 30 seconds. After increasing the timeout at I was successfully able to connect the server. My question is how I can do same in this websocket library or override some function of library. Any input on this will be of great help.
from nv-websocket-client.
Now I had get solution to the above problem. When hostname is IP address InetSocketAddress constructor fill addr field and make HostName file null. During actual SSL connection it tries to get hostname via reverse DNS lookup. As I only want to create tls connection via IP so I injected hostname into InetSocketAddress I modified toInetSocketAddress() function of Address.java
InetSocketAddress toInetSocketAddress()
{
try {
InetAddress addr = InetAddress.getByName(mHost);
Log.d("InetsocketAddress call","before call");
injectHostname(addr,mHost);
return new InetSocketAddress(addr, mPort);
}
catch ( Exception e)
{
Log.d("InetsocketAddress fail", e.getMessage());
return new InetSocketAddress(mHost, mPort);
}
}
private void injectHostname(InetAddress address, String host) {
try {
Field field = InetAddress.class.getDeclaredField("hostName");
field.setAccessible(true);
field.set(address, host);
} catch (Exception ignored) {
}
}
from nv-websocket-client.
Related Issues (20)
- getting below when i try subscribe my payload from Server sometimes
- getting below errors after socket opened and when i try to subscribe my payload from Server sometimes HOT 3
- why getListenerManager() getStateManager() and others are private ? HOT 1
- Denied app upload to PlayStore HOT 3
- How can I have a listener for each sendText Method? HOT 1
- Very misleading error message if jdk.crypto.ec module is missing
- NV WebSocket Client & Quarkus & GraalVM Native Image Problems HOT 1
- Race between WebSocketAdapter.onConnected() and .onTextMessage().
- websocket client send performance
- While multiple send, download is blocked
- -
- Crashes on API < 24 with new AGP that is needed for API 33 HOT 8
- Websocket disconnects automatically after 30 seconds HOT 3
- Handshake failure with basic Authorization
- Websocket makes two connections HOT 1
- how to get session id to send messages
- Throws Exception even if the url is valid
- Does the library use some Tracking link?
- Upgrade SHA-1 to SHA-256 in HandshakeReader
- Ability to replace threads
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nv-websocket-client.