Web socket connection was successful with 101 protocol change but facing error while getting message from server - spring

Using spring web socket server side for constant updates from the server to client (ionic application is the client), using STOMP for connectivity.
Facing issue after getting connected. "Unhandled frame: stomp.js:134 <<< c[1007,"null"]" at client side and "com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'CONNECT': was expecting ('true', 'false' or 'null')" error is observed at server.
Console log at client side :
Opening Web Socket...
Web Socket Opened...
CONNECT
accept-version:1.1,1.0
heart-beat:10000,10000
<<< o
Unhandled frame:
<<< c[1007,"null"]
Unhandled frame:
content-length:13
[1007,"null"]
Whoops! Lost connection to ws://127.0.0.1:8080/...

If you use SockJS with Stomp on Java Spring, you must encapsulate your Stomp frame with socket JS protocol.
for send "CONNECT\naccept-version:1.1,1.0\nheart-beat:10000,10000\n\n" + String.fromCharCode(0)
you must send this frame: "[\"CONNECT\\naccept-version:1.1,1.0\\nheart-beat:10000,10000\\n\\n\\u0000\"]"
dart code:
String data = "CONNECT\naccept-version:1.1,1.0\nheart-beat:10000,10000\n\n" + String.fromCharCode(0);
data = "[${json.encode(data)}]";
Or if you don't use Sock JS
try change (char)0 inside stomp frame by \u0000

Related

connection lost when waiting for connack response using mqtt websockets for ibm bluemix watson iot

I'm able to perform ssl & websocket handshake. The http connection is getting upgraded to websocket connection which is fine. The erlang websocket client is getting connected to the IBM Bluemix server.
But after some time I receive ssl_closed response which closes down the connection. I was sending ping request to the server and was getting response for it in binary format (which might be pong ({binary,<<10,0>>} .. haven't decoded the binary response frame).
SockReply : {ok,{sslsocket,{gen_tcp,#Port<0.2284>,tls_connection,undefined}, <0.52.0>}}
Socket : {sslsocket,{gen_tcp,#Port<0.2284>,tls_connection,undefined}, <0.52.0>} [debug] [d:6xxxxx:myFybr123:streetlight_123#172.16.1.237:57054]
SENT: CONNECT(Q0, R0, D0, ClientId=d:6xxxxx:myXXXX123:streetlight_123, ProtoName=MQTT, ProtoVsn=3, CleanSess=true, KeepAlive=300, Username=use-token-auth, Password=**)
[info] [Client <0.36.0>] connected with wss://6xxxxx.messaging.internetofthings.ibmcloud.com:443
[warning] [Client <0.36.0>] Connection lost for: ssl_closed when state is waiting_for_connack
Message : {ssl_closed, {sslsocket, {gen_tcp,#Port<0.3922>,tls_connection,undefined}, <0.74.0>}}
Why am I receiving ssl_closed after getting connected?

Javascript Adapter throwing java.net.SocketException: Connection reset

I am trying to make a https call to the backend server that gives a json data , i could get the by making https calls using browser but when make the same call using the javascript adapter i getting this output
I followed this IBM Knowledge Center to add the cert to the default mobilefirst keystore. I am not sure why i am getting this error?
[ERROR ] FWLSE0099E: An error occurred while invoking procedure [project kmf]login/HttpRequestFWLSE0100E: parameters: [project kmf]
Http request failed: java.net.SocketException: Connection reset
FWLSE0101E: Caused by: [project kmf]java.net.SocketException: Connection resetjava.lang.RuntimeException: Http request failed: java.net.SocketException: Connection reset
at com.worklight.adapters.http.HTTPConnectionManager.execute(HTTPConnectionManager.java:271)
at com.worklight.adapters.http.HttpClientContext.doExecute(HttpClientContext.java:201)
at com.worklight.adapters.http.HttpClientContext.execute(HttpClientContext.java:185
From the comments, by Vivin:
Connection reset means , the backend server has reset the connection. You should consult your network team/ backend team and verify why this occuring. Firewalls / network issues / backend server connection issues are all possibilities. MobileFirst server is only reporting the issue as it found

Websockify server + socket.io client

Im trying to connect from a client using socket.io :
<script src="https://cdn.socket.io/socket.io-1.3.5.js"></script>
<script>
var socket = io.connect('http://127.0.0.1:8000');
</script>
to a server running websockify to translate websocket traffic to normal tcp, im running it using the latest releases and :
./run 8000 :5000
but this error ocurrs:
WebSocket server settings:
- Listen on :8000
- Flash security policy server
- No SSL/TLS support (no cert file)
- proxying from :8000 to :5000
127.0.0.1 - - [30/Nov/2015 21:23:46] code 405, message Method Not Allowed
from what i have read this happens if you send a POST request to a server that doesnt allow it, is this whats causing this error? is there any way to configure websockify to accept such request?

Websockify base64: 'False'

When I'm starting websockify with python2.7 on my server no warnings appear, everything is ok.
But when the first connection comes in there are problems with base64 I think:
1: <ip>: Plain non-SSL (ws://) WebSocket connection
1: <ip>: Version hybi-13, base64: 'False'
1: connecting to: <myserver.com>:64749
On the client side I get an error in safari but it also tells me that the connection is made and I'm able to send and receive messages:
WebSocket network error: The operation couldn’t be completed. Connection refused ws://localhost:17523
The error about connecting to ws://localhost:17523 is harmless. In order to test whether the WebSocket API supports binary data it is necessary to actually instantiate a WebSocket object, however, WebSocket objects must be instantiated with an actual destination so websock.js uses a localhost port to test the connection. The browser complains that the connection fails but websock.js is able to use that object to do its test.
The base64: False indicates that the client and server have negotiated to use raw binary data and don't need to use base64 encoded strings to encode the data. Base64 encoding is necessary in older browsers (or with web-socket-js emulator) that support WebSockets but not binary data.
Since you are successfully sending and receiving data, I assume this question is just verifying that the messages you are seeing aren't major problems correct?

how to connect http server implemented by the c# socket class

I have finished http protocol via the socket class according to rfc2616 protocol, but how to connect https protocol and send data to server using the socket class?
When i connected https server https://www.example.com, I always get 404 error. The following is the socket command that to send to server https://www.example.com/
GET / HTTP/1.1 Host: www.example.com
the default always use http protocol
I found connected to https server need to use a connect command instead of the Get command and a client certificate. for example:
CONNECT login.example.com:443 HTTP/1.0
Major Version: 3
Minor Version: 1
......
I will try to use the connect command. Thanks for your replies.
==================================================
OK,i have solved my problem ,use the SLStream class.
NetworkStream networkStream=new NetWorkStream(socket)
var stream=New SslStream(networkStream)
.......
Now, will can read stream and write stream, until finished.

Resources