websocket.h E_INVALID_PROTOCOL_FORMAT WebSocketEndClientHandle [英] websocket.h E_INVALID_PROTOCOL_FORMAT WebSocketEndClientHandle

查看:217
本文介绍了websocket.h E_INVALID_PROTOCOL_FORMAT WebSocketEndClientHandle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在制作一个应用程序,当你在锁定屏幕上按键盘时,我的软电话会自动接听来电,这样我就不会错过它在房间的另一端。

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.

我看到Windows有网络套接字,所以我想用它们来防止必须链接库。

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

我遇到的问题是WebSocketEndClientHandshake。它总是返回E_INVALID_PROTOCOL_FORMAT。

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

我创建了一个websocket句柄。

I have created a websocket handle.

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

然后运行WebSocketBeginClientHandshake。

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; }

此返回的S_OK。然后我写出了这样的标题数组:

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[i].pcName << "x" << responceHeaders[i].ulNameLength << ":" << responceHeaders[i].pcValue << "x" << responceHeaders[i].ulValueLength << std::endl;
}

显示:

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

然后我将这些标题添加到我的标题数组中,将其替换为名称相同的标题。我不会因为这篇文章而粘贴代码会变长有一个github链接,如果需要,我可以稍后发布。

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

然后我将这些标题传递给WebSocketEndClientHandshake以及一些ULONG指针:

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);

我试过将返回的头文件从BeginClientHandshake传递给EndCliendHandshake,并且还返回了无效的格式。

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

我修改了我的主机头以获得服务器地址为无意义的"sdfkbsdf"看看它做了什么,没有任何变化,BeginHandshake仍然成功,EndHandshake失败。所以我想知道它是否与我的主机标题有关,结构为
,如下所示:

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?

谢谢。




推荐答案

感谢您在此处发帖。

>> websocket.h E_INVALID_PROTOCOL_FORMAT WebSocketEndClientHandle

请提供有关用于初始化WEB_SOCKET_HTTP_HEADER的值的更多信息。

Please provide more information about the values you used to initial the WEB_SOCKET_HTTP_HEADER.

正如文档所述,  WEB_SOCKET_HTTP_HEADER数组应该包含主机HTTP
RFC 2616 中定义的标题。

As the document says, the WEB_SOCKET_HTTP_HEADER array should include the Host HTTP header as defined in RFC 2616.

此外,名称 WEB_SOCKET_HTTP_HEADER 的值不应包含冒号字符。

Besides, the name value of the WEB_SOCKET_HTTP_HEADER shouldn't contain a colon character.

由于MSDN中没有关于Web套接字的更多信息,如果这些信息无法帮助您,请在下面的论坛上发布此问题。

Since there hasn't more information about the web socket in MSDN, if these information couldn't be help of you, please post this issue on this forum below.

https://developercommunity.visualstudio.com/spaces/8/index.html

您的理解与合作将不胜感激。

Your understanding and cooperation will be grateful.

最好的问候,

Baron Bi


这篇关于websocket.h E_INVALID_PROTOCOL_FORMAT WebSocketEndClientHandle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆