websocket.h E_INVALID_PROTOCOL_FORMAT WebSocketEndClientHandle

  • Thread starter Thread starter Gandhi MagicFingers
  • Start date Start date
G

Gandhi MagicFingers

Guest
been making an app for work to automatically answer a call on my soft phone when your hit your keyboard on the lock screen so I don't miss it when at the other end of the room.

I saw windows has web sockets, so I thought to use their one to prevent having to link libraries.

The issue I have is WebSocketEndClientHandshake . It always returns E_INVALID_PROTOCOL_FORMAT.

I have created a websocket handle.

if (WebSocketCreateClientHandle(NULL, 0, &socket_handle) != S_OK) {
Log::LogMessage("WebSocketCreateClientHandle Failed", Log::LOGLEVEL::CRITICAL);
return 1;
}

Then ran WebSocketBeginClientHandshake .


// if handshake is successful, these will be populated
WEB_SOCKET_HTTP_HEADER* responceHeaders = nullptr;
ULONG responceHeadderCount;
if (WebSocketBeginClientHandshake(socket_handle, NULL, 0, NULL, 0, &headers[0], 1, &responceHeaders, &responceHeadderCount) != S_OK) {
return -1;
}


This returned S_OK. I then wrote out the array of headers like this:

// name nameLength, value valuelength
for (int i = 0; i < responceHeadderCount; i++) {
std::cout << responceHeaders.pcName << "x" << responceHeaders.ulNameLength << ":" << responceHeaders.pcValue << "x" << responceHeaders.ulValueLength << std::endl;
}

which shows:

Sec-WebSocket-Keyx17:r7XbrevEUv6awqPe24f0Ww==┐å⌐≤w2x24
Connectionx10:Upgradex7
Upgradex7:websocketx9
Sec-WebSocket-Versionx21:13x2

I then add these headers to my array of headers, replacing mine with theirs where the names are the same., i wont bother pasting the code as this post will get long. there is a github link and i can post it later if need be.

This then created a header array like this:

Host:demos.kaazing.com:443
Sec-WebSocket-Key:9RuzRpCi5rJzqPTw2vPrNQ==
Connection:Upgrade
Upgrade:websocket
Sec-WebSocket-Version:13

I then pass these headers to WebSocketEndClientHandshake as well as some ULONG pointers:


ULONG selected_subprotocol;
ULONG selected_extensions;
ULONG selected_extensions_count;
HRESULT result = WebSocketEndClientHandshake(socket_handle, responceHeaders,
responceHeadderCount, &selected_extensions,
&selected_extensions_count, &selected_subprotocol);


I have tried just passing the returned headers from BeginClientHandshake to EndCliendHandshake and that also returned invalid format.

I modified my Host header to have the server address as nonsense"sdfkbsdf" to see what it does and nothing changes, BeginHandshake still succeeds and EndHandshake fails. So I am wondering if it is something to do with my Host header which is structured as follows:

WEB_SOCKET_HTTP_HEADER* Socket::CreateHeader(const std::string &pName, const std::string &pValue) {
WEB_SOCKET_HTTP_HEADER* header = new WEB_SOCKET_HTTP_HEADER;

PCHAR name = new CHAR[pName.length()];
pName.copy(name, pName.length());
header->ulNameLength = pName.length();
header->pcName = name;

PCHAR value = new CHAR[pValue.length()];
pValue.copy(value, pValue.length());
header->pcValue = value;
header->ulValueLength = pValue.length();

return header;
}

Does anyone have any idea what is wrong here?

Thanks.

Continue reading...
 
Back
Top