Windows 8 MessageWebSocket http请求垃圾

时间:2013-01-22 22:04:21

标签: windows-8 websocket c++-cx

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

C8 D7 19 87 09 1C C8 60 00 13 8C FA 08 00 45 00 00 C3 37 78 40 00 80 06 00 00 C0 A8 01 71 17 17 5C 67 C2 4F 01 BB 06 1A 36 71 A2 8B 48 C7 50 18 04 00 36 4D 00 00 47 45 54 20 2F 20 48 54 54 50 2F 31 2E 31 0D 0A 53 65 63 2D 57 65 62 53 6F 63 6B 65 74 2D 4B 65 79 3A 20 76 46 46 30 4F 4C 2F 55 63 53 49 6E 6F 70 46 67 52 69 6F 52 73 77 3D 3D 0D 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 65 62 73 6F 63 6B 65 74 0D 0A 53 65 63 2D 57 65 62 53 6F 63 6B 65 74 2D 56 65 72 73 69 6F 6E 3A 20 31 33 0D 0A 48 6F 73 74 3A 20 32 33 2E 32 33 2E 39 32 2E 31 30 33 3A 34 34 33 0D 0A 0D 0A È×.‡..È`..Œú..E..Ã7x@.€...À¨.q..\gÂO.»..6q¢‹HÇP...6M..GET / HTTP/1.1..Sec-WebSocket-Key: vFF0OL/UcSInopFgRioRsw==..Connection: Upgrade..Upgrade: Websocket..Sec-WebSocket-Version: 13..Host: 192.168.1.1:443....(在大多数情况下,点是\ r \ n)

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

在C ++中,我正在创建websocket:

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

我在代码中看不到任何问题,所以我希望其他一些眼睛可以。感谢。

1 个答案:

答案 0 :(得分:1)

您粘贴的内容似乎是Ethernet frame,但剥离了8个字节(7字节前导码和1字节起始帧分隔符),因为网络接口没有接收到它。

前十四个字节是Ethernet header:目标MAC地址为6个字节,源MAC地址为6个字节,EtherType为2个字节,08 00表示它是IPv4数据包。

以太网有效负载遵循以太网报头,在这种情况下,是IP datagram,因此它以偏移量为14的IP header开头,字节45表示带有标头长度为20个字节。在偏移量23处,您将找到表示TCP的06的IP协议。在偏移量26处,您将找到源IP地址(C0 A8 01 71,即192.168.1.113)。在偏移量30处,您将找到目标IP地址。

IP有效负载遵循IP标头,在这种情况下,它是TCP segment,以TCP header开头,偏移量为34,字节C2 4F表示源端口为49743,字节01 BB表示目标端口为443.在偏移量46处,您有50表示TCP标头长度为20个字节。

TCP有效负载遵循TCP标头,在这种情况下,HTTP从偏移54开始,字节47 45 54 ...为“GET ...”。

此请求数据包似乎已正确完成。我相信你的问题在于其他地方。

相关问题