Windows 8 Windows 8 MessageWebSocket http请求垃圾

Windows 8 Windows 8 MessageWebSocket http请求垃圾,windows-8,websocket,c++-cx,Windows 8,Websocket,C++ Cx,我正在开发一个Windows 8应用程序,它使用node.js/socket.io与node.js服务器通信,在连接方面遇到了一大堆问题。我决定运行一个tcp嗅探器应用程序(microsoft network monitor 3.4),并注意到在发送http请求之前,我的字符串中有一堆垃圾: C8 D7 19 87 09 1C C8 60 00 13 8C FA 08 00 45 00 C3 37 78 40 00 80 06 00 C0 A8 01 71 17 5C 67 C2 4F 01 B

我正在开发一个Windows 8应用程序,它使用node.js/socket.io与node.js服务器通信,在连接方面遇到了一大堆问题。我决定运行一个tcp嗅探器应用程序(microsoft network monitor 3.4),并注意到在发送http请求之前,我的字符串中有一堆垃圾:

C8 D7 19 87 09 1C C8 60 00 13 8C FA 08 00 45 00 C3 37 78 40 00 80 06 00 C0 A8 01 71 17 5C 67 C2 4F 01 BB 06 1A 36 71 A2 8B 48 C7 50 18 04 00 36 4D 00 47 45 54 20 2F 20 48 54 50 2F 31 0D 53 65 65 2D 57 62 53 6 F 63 74 2D 4B 65 79 3A 20 76 46 30 4F 4C 55 53 53 49 6 E 6 F 70 46 67 52 69 6F 52 73 3D0D 0A 43 6F 6E 6E 65 63 74 69 6F 6E 3A 20 55 70 67 72 61 64 65 0D 0A 55 70 67 72 61 64 65 3A 20 57 62 73 6F 63 6B 65 74 0D 0A 53 65 63 2D 57 62 53 6F 63 6B 65 74 2D 56 65 72 73 69 6F 6E 3A 20 31 33 0D 48 6F 73 74 3A 20 32 33 2 E 32 33 2 E 39 32 2 E 31 30 33 34 34 34 34 0D 0A 0D 0A
È×.‡..È`..Œú..E7x@.;;

虽然我使用的是端口443,但这不是一个安全的websocket-我被迫使用443,因为一些智能手机只允许websocket在该端口上创建套接字连接

在C++中,我创建了这样的WebSoCo,例如:

void Websocket::Connect(Platform::String ^host)
{
  if ( this->socket != nullptr ) return;
  try
  {
    Uri^ address = ref new Uri(host);
    readBuffer = ref new Buffer(1000);
    this->socket = ref new MessageWebSocket();
    this->socket->Control->MessageType = SocketMessageType::Utf8;
    this->socket->Control->MaxMessageSize = 512;
    this->socket->Closed += ref new TypedEventHandler<IWebSocket^, WebSocketClosedEventArgs^>( this, &Websocket::ServerClosed );
    this->socket->MessageReceived += ref new TypedEventHandler<MessageWebSocket^, MessageWebSocketMessageReceivedEventArgs^>( this, &Websocket::MessageRecv );
    create_task(this->socket->ConnectAsync(address)).then([this](task<void> previousTask)
    {
      try
      {
        concurrency::task_status status = previousTask.wait();
        switch( status ) {
        case concurrency::task_status::completed:
          this->connected = true;
          break;
        default:
          socketErrorString = ref new Platform::String( L"Connection was cancelled" );
        }
      }
      catch(Exception^ exception)
      {
        this->connected = false;
        socketErrorString = ref new Platform::String( exception->Message->Data() );
        this->socket = nullptr;
      } catch( ... ) {
        this->connected = false;
        socketErrorString = ref new Platform::String( L"Unknown exception caught (inside connect)" );
        this->socket = nullptr;
      }
    });
  } catch( Exception ^exc ) {
    this->connected = false;
    socketErrorString = exc->Message; //ref new Platform::String( L"Unknown exception caught (outside connect)" );
    this->socket = nullptr;
  }
}
void Websocket::Connect(平台::字符串^host)
{
if(this->socket!=nullptr)返回;
尝试
{
Uri^address=ref新Uri(主机);
readBuffer=ref新缓冲区(1000);
this->socket=ref新消息websocket();
此->套接字->控件->消息类型=SocketMessageType::Utf8;
此->套接字->控件->MaxMessageSize=512;
this->socket->Closed+=ref新类型deventhandler(this,&Websocket::ServerClosed);
this->socket->MessageReceived+=ref新类型deventhandler(this,&Websocket::MessageRecv);
创建_任务(此->套接字->连接异步(地址))。然后([此](任务前一个任务)
{
尝试
{
并发::task_status status=previousTask.wait();
开关(状态){
案例并发::任务状态::已完成:
此->已连接=真;
打破
违约:
socketErrorString=ref新平台::String(L“连接被取消”);
}
}
捕获(异常^Exception)
{
此->已连接=错误;
socketErrorString=ref新平台::String(异常->消息->数据());
此->套接字=空ptr;
}捕获(…){
此->已连接=错误;
socketErrorString=ref new Platform::String(L“捕获未知异常(内部连接)”);
此->套接字=空ptr;
}
});
}捕获(异常^exc){
此->已连接=错误;
socketErrorString=exc->Message;//ref new Platform::String(L“捕获未知异常(外部连接)”);
此->套接字=空ptr;
}
}

我在代码中看不到任何问题,所以我希望其他几组人也能看到。谢谢。

您粘贴的内容似乎是一个,但由于网络接口没有接收到它,因此被剥离了8个字节(7个字节的前导和1个字节的开始帧分隔符)

前14个字节是:6个字节用于目标MAC地址,6个字节用于源MAC地址,2个字节用于,其中
08 00
表示它是IPv4数据包

以太网有效负载跟随以太网报头,在本例中,它是一个,因此它从偏移量14开始,字节
45
表示报头长度为20字节的IPv4报头。在偏移量23处,您可以找到表示TCP的IP协议
06
。在偏移量26处,您将找到源IP地址(
C0 A8 01 71
,即192.168.1.113)。在偏移量30处,您将找到目标IP地址

IP有效负载跟随IP报头,在这种情况下,它是从at偏移量34开始的,字节
C2 4F
表示源端口49743,字节
01 BB
表示目标端口443。在偏移量46处有
50
,表示TCP头长度为20字节

TCP负载跟随TCP报头,在本例中,从偏移量54开始,字节
47 45 54…
为“GET…”


此请求数据包似乎格式正确。我相信你的问题在别处

您使用的主机的价值是什么?是否加了ws://前缀(不确定这是否有助于迫使MessageWebSocket使用HTTP而不是HTTPS,但值得一试)?我指定的是“ws://192.168.1.1:443/”,实际上,现在我仔细看看您粘贴的内容(以及您可以读取请求明文的事实),似乎您粘贴了一个完整的以太网帧。前14个字节可能是以太网报头,然后是IP报头(从
45 00 C3
开始),然后是TCP报头(从
C2 4F 01 BB
开始;注意
01 BB
是您的目标端口443),然后是TCP负载(从
47 45 54 20
开始;请求数据)。没有使用TLS。您有权访问节点服务器的日志吗?请求通过了什么?也就是说:请求包看起来很好,问题在别处。如果你在回答中抛出你的回答,我会将其标记为接受。