I have a problem with QWebSocket connection with C++.
QWebSocket *mWebSocket = new QWebSocket();
connect(mWebSocket, SIGNAL(connected()), this, SLOT(connected()));
connect(mWebSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(mWebSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
QNetworkRequest lRequest(QUrl("wss://gateway-predix-data-services.run.aws-usw02-pr.ice.predix.io/v1/stream/messages"));
lRequest.setRawHeader("Predix-Zone-Id", <my unique id>);
lRequest.setRawHeader("Authorization", <some token>);
mWebSocket->open(lRequest);
I am getting 3 errors and then disconnect, but never connect.
called slot: error
QAbstractSocket::RemoteHostClosedError
called slot: error
QAbstractSocket::ConnectionRefusedError
called slot: error
QAbstractSocket::RemoteHostClosedError
called slot: disconnected
When I make a small typo in my token (to test if authentication is ok), I am starting receiving only QAbstractSocket::ConnectionRefusedError error.
The most interesting part is that I have implemented websocket connection with python and it works very good, so the problem should not be from websocket server part, or request header setup:
import websocket
import thread
import time
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
def run(*args):
for i in range(3):
time.sleep(1)
#ws.send('{messageId: 1453338376222,body: [{name: Compressor-2017:CompressionRatio,datapoints: [[1453338376222,10,3],[1453338377222,10,1]],attributes: {host: server1,customer: Acme}}]}')
time.sleep(1)
#ws.close()
print("thread terminating...")
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://gateway-predix-data-services.run.aws-usw02-pr.ice.predix.io/v1/stream/messages",
on_message = on_message,
on_error = on_error,
on_close = on_close,
header = {'Predix-Zone-Id:my unique id', 'Authorization:token'}
)
ws.on_open = on_open
ws.run_forever()
This websocket connection is part of of my c++ sdk, so I need it to be implemented with c++. Do you have any ideas what I have missed in my C++ code?