nv-websocket-client icon indicating copy to clipboard operation
nv-websocket-client copied to clipboard

Socket connectivity issue

Open Ramkesh9 opened this issue 7 years ago • 6 comments

Hi, error :- com.neovisionaries.ws.client.WebSocketException: The status line of the opening handshake response is empty. i am getting problems while connecting with socket from my android app, can any one give me complete source code or help me with how to connect mobile app with my socket server . i am using this url -> " WebSocket ws = factory.cr eateSocket("ws://service.arunlogistics.com:8001", 5000);" it needs to headers -> ws.addHeader("token", "7d2ce13ef67e34468b6b5d201008ec8d1c836182"); -> ws.addHeader("vehicle", "PB10EX1060");

--> yesterday it was connected once by chance , but not reconnected again, till now

i also attached my source code ,so you can see my code for where i am lacking , its urgent, so any help will be appreciable . socketconnection.txt

Ramkesh9 avatar Jul 17 '17 08:07 Ramkesh9

ws.addHeader("token", "7d2ce13ef67e34468b6b5d201008ec8d1c836182");
ws.addHeader("vehicle", "PB10EX1060");

will generate HTTP headers like below

token: 7d2ce13ef67e34468b6b5d201008ec8d1c836182
vehicle: PB10EX1060

Is this really what you want to do?

The name of token implies that the WebSocket endpoint is protected by a security token such as OAuth 2.0 access token. Why don't you ask the implementer of the WebSocket endpoint about how the endpoint is protected?

TakahikoKawasaki avatar Jul 17 '17 09:07 TakahikoKawasaki

i need to pass this header for auth and get connected with websocket , so what should i do?

Ramkesh9 avatar Jul 17 '17 09:07 Ramkesh9

For example, in normal cases, OAuth 2.0 access tokens are presented to APIs as follows as defined in RFC 6750, 2.1. Authorization Request Header Field.

Authorization: Bearer {access-token}

I don't know how your WebSocket endpoint is protected, however, the following HTTP header:

token: 7d2ce13ef67e34468b6b5d201008ec8d1c836182

looks abnormal. Therefore, it is worth checking again how to pass the token parameter to the WebSocket endpoint.

TakahikoKawasaki avatar Jul 17 '17 09:07 TakahikoKawasaki

And, just FYI.

Basic Authentication is another often-used way. If an API is protected by Basic Authentication, you have to pass:

Authorization: Basic {credentials}

{credentials} above is a Base64 representation of id:password.

TakahikoKawasaki avatar Jul 17 '17 09:07 TakahikoKawasaki

can you assit me some for header sennding ?

Ramkesh9 avatar Jul 17 '17 09:07 Ramkesh9

At this moment, I cannot help you any more because I don't know the specification of the WebSocket endpoint.

First, investigate how the WebSocket endpoint is protected. Second, tell me the specification. Then, I'll be able to explain how to use nv-websocket-client APIs to comply with the specification.

TakahikoKawasaki avatar Jul 17 '17 09:07 TakahikoKawasaki