- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图编写一些C++代码来控制我的Philips Hue灯。在使用浏览器调试工具找出网桥的IP并添加了一个用户来控制灯光之后,我尝试用代码复制浏览器发送的消息以创建自己的例程。
这是我正在使用的代码:
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <string>
#pragma comment(lib, "Ws2_32.lib")
#define PORT "80"
int main() {
const char* adress = "192.168.178.x";
// Initializing Winsock
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); //MAKEWORD(2, 2) specifies the version
if (iResult != 0)
{
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
// Data structure to hold info for the socket
struct addrinfo *result = NULL,
*ptr = NULL,
hints;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET; // Only using IPv4 adresses
hints.ai_socktype = SOCK_STREAM; // TCP socket
hints.ai_protocol = IPPROTO_TCP;
// Converting adress to readable format and stuffing it into result.
iResult = getaddrinfo(adress, PORT, &hints, &result);
if (iResult != 0)
{
printf("getaddrinfo failed: %d\n", iResult);
WSACleanup();
return 1;
}
// Actually creating a socket
SOCKET ConnectSocket = INVALID_SOCKET;
ptr = result;
// Creating socket with previously initialized data
ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
if (ConnectSocket == INVALID_SOCKET)
{
printf("Error at socket(): %ld\n", WSAGetLastError());
freeaddrinfo(result);
WSACleanup();
return 1;
}
// Connecting to the server socket
iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
// Error checking
if (iResult == SOCKET_ERROR)
{
closesocket(ConnectSocket);
ConnectSocket = INVALID_SOCKET;
}
freeaddrinfo(result);
if (ConnectSocket == INVALID_SOCKET)
{
printf("Unable to connect to server!\n");
WSACleanup();
return 1;
}
/////////////////////////////////////////////////////////
// ACTUAL MESSAGE
std::string request = "GET /api/<username>/lights/2 HTTP/1.1\r\n";
request.append("Host: 192.168.178.x\r\n");
request.append("\r\n");
////////////////////////////////////////////////////////
printf("Request:\n%s", request.c_str());
// Send message
iResult = send(ConnectSocket, request.c_str(),(int) request.size(), 0);
// Error check
if (iResult == SOCKET_ERROR)
{
printf("send failed: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
printf("Bytes Sent: %ld\n", iResult);
// Shutting down socket since it won't be used anymore (can still receive data)
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR)
{
printf("shutdown failed: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
const int buflen = 8196;
char recvbuf[buflen];
ZeroMemory(recvbuf, buflen);
// Keep socket open until connection is closed
do
{
iResult = recv(ConnectSocket, recvbuf, buflen, 0);
if (iResult > 0)
{
printf("Bytes received: %d\n", iResult);
printf("\nResponse:\n%s\n", recvbuf);
}
else if (iResult == 0)
{
printf("Connection closed\n");
}
else
{
printf("recv failed: %d\n", WSAGetLastError());
}
} while (iResult > 0);
closesocket(ConnectSocket);
WSACleanup();
return 0;
}
如果查看此问题的编辑历史记录,您会发现我以前认为我的HTTP消息有问题,但是发现了一些奇怪的行为:
最佳答案
经过一番尝试和错误后,我发现了一些使之起作用的方法。
如果我把这一部分:
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR)
{
printf("shutdown failed: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
在接收消息的部分之后,它可以工作。
关于c++ - 尝试控制Philips Hue Lights时,未从桥接器获得任何响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63084739/
我需要为我正在处理的应用程序使用 Surface 项目模板,但我也想使用 MVVM Light Toolkit。我发现我可以“添加 | 新项目...”并为 View 、 View 模型或定位器选择一个
我正在使用MVVM Light,并且正在使用消息在ViewModel之间进行通信,以使ViewModel知道何时可以执行某些操作。我的问题是我注册了一条消息,然后多次收到它。因此,要使我的程序不止执行
我目前正在自学MVVM模式。 我第一次碰到了消息传递的概念。 我知道消息传递包含在mvvm-light工具包中。但是我找不到任何地方的用法示例(下载中未提供示例项目)。 如果有人可以指导我了解有关如何
使用Nuget安装MVVM Light Toolkit时,似乎没有安装MVVM Light的片段。 我在哪里可以找到它们? 最佳答案 片段可在 GitHub 上找到. 下载代码(右上角克隆或下载按钮)
我遇到了一个问题,即在 VS 或 Blend 中运行解决方案时,属性 IsInDesignMode 没有返回 true 的预期值。我的环境包括 Win Server 2008 R2、VS2010 Pr
如果我将消息从 ViewModelA 发送到 ViewModelB,是否有办法从我的单元测试中捕获此通知,该单元测试正在测试引发消息的 ViewModelA? Messenger.Default.Se
我尝试使用提供的示例 petstore openapi.json 生成项目。我用过light-codegen生成端点和模型。 我确实安装了 light-codegen: git clone https
这段代码告诉计算机做什么?附注“灯”是一个 boolean 数组。 for (int k = 1; k < lights.length; k++) lights[k]
我有一个包含几个对象和一些对象的场景,在这些情况下,我希望球体受到粉红色和蓝色灯光的影响。但我也有一个管几何结构,它应该只受白光影响,而不受粉红色和蓝色光的影响。 有关问题的演示,请参见下图:现在发生
我正在考虑开始使用 MVVM Light,并且遇到了"new"ICleanup 界面。我只是想知道你什么时候清理虚拟机......当你离开页面时? 另外,我看到 ViewModelLocator 中有
我有一个带有关联虚拟机的子窗口,每次我要求打开子窗口时都会创建该虚拟机。当子窗口打开时,它会为 MVVM Light 消息注册一个监听器。关闭窗口后,我很确定我正在释放对它的所有引用,但我实际上并没有
是否有 MVVM Light DispatcherHelper 可用于 PCL 的时间表?官博中只有备注,暂时不可用。 最佳答案 我刚刚添加了一个 nuget 包,它可以帮助您从 MvvmLight
我正在尝试按照此博客文章中的示例使用 MVVM Light 框架来实现 Metro 风格的分组项目页面,但使用 ViewModelLocator 来提供可混合性: http://mikaelkoski
我们有一个使用 MVVM Light 的 WP8 应用程序,它运行良好。但是,现在我们要使用 Xamarin 来定位 iOS。看来 MvvmCross 是更好的跨平台开发框架。 有没有人有改变这样的框
刚刚注意到 4.2.30 版本不包括 protected bool Set( ref T field, T newValue,
我已经开始使用最新的 MVVM Light 工具包 v4(NuGet 预览版 v4.1.21,DLL v:4.0.21.25725),它实现了 SimpleIOC 模式。 在我的 ViewModelL
我可以使用 Interaction.Triggers 捕获文本框上的 textchanged 事件,如下所示:
我希望这不是一个太愚蠢的问题:我刚刚开始使用 MVVM light(到目前为止很喜欢它!)。在“之前”(即使用 MVVML 之前),我必须通过 ui 分派(dispatch)任何会命中引发 INoti
我在 list 中使用了以下行: android:theme="@android:style/Theme.Light.NoTitleBar" 没有标题栏并在我的应用程序中显示精简版的 AlertDia
“ChainLight”类在其构造函数中有一个名为“rayDirection”的参数: ChainLight(rayHandler, rays, Color, distance, rayDirecti
我是一名优秀的程序员,十分优秀!