POCO 1.5.1 Websocket客户端无法连接到c#Websocket服务器

POCO 1.5.1 Websocket客户端无法连接到c#Websocket服务器,c#,c++,websocket,poco,eventmachine,C#,C++,Websocket,Poco,Eventmachine,问题: websocket客户端(POCO 1.5.1,c++)将不会连接到websocket c#服务器(带有Fleck库的命令行应用程序)。到达超时时抛出异常: Cannot upgrade to WebSocket connection: OK Exception Code: 1 Poco WebException Documentation WS_ERR_NO_HANDSHAKE = 1 : No Connection: Upgrade or Upgrade: websocket h

问题:

websocket客户端(POCO 1.5.1,c++)将不会连接到websocket c#服务器(带有Fleck库的命令行应用程序)。到达超时时抛出异常:

Cannot upgrade to WebSocket connection: OK
Exception Code: 1

Poco WebException Documentation
WS_ERR_NO_HANDSHAKE = 1 : 
No Connection: Upgrade or Upgrade: websocket header in handshake request.
事实1:这个websocket客户端将连接到一个Ruby事件机websocket服务器

事实2:javascript客户端将连接到websocket c服务器

事实3:相同的javascript客户端也将连接到websocket ruby服务器

事实4:websocket客户端将不会连接到Alchemy websocket服务器附近

使用Wireshark更新 POCO正在使用 GET/HTTP/1.0\r\n

Javascript版本: GET/HTTP/1.1\r\n


所有源代码 C++中的客户端代码
问题是POCO默认HTTP请求版本为1.0

RFC规范第4.1节指出,最小值为1.1:

  • 请求的方法必须是GET,HTTP版本必须是GET 至少为1.1。 例如,如果WebSocket URI为“ws://example.com/chat”, 发送的第一行应该是“GET/chat HTTP/1.1”
  • 通过将HTTPRequest结构替换为:

    HTTPRequest request(HTTPRequest::HTTP_GET, "/ws", "HTTP/1.1" );
    

    干杯

    您得到的确切错误代码是什么?您从哪里得到的?有趣的是,服务器在客户端超时之前检测到客户端连接。>>2013年11月24日下午4:30:01【调试】客户端从127.0.0.1:64699连接2013年11月24日下午4:30:01【调试】155字节读取与POCO异常文档交叉引用:WS_ERR_NO_HANDSHAKE=1无连接:升级或升级:握手请求中的websocket头。在POCO源代码中,这个错误意味着服务器没有包含Upgrade:websocket头。您应该使用数据包嗅探器(如Wireshark)来查看TCP对话。使用斑点或炼金术似乎可以与HTML/javascript客户端一起工作。我觉得POCO是这里的问题。
    // vs2010
    // fleck library
    // Windows 7 enterprise edition
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    using Fleck;
    using System.Timers;
    
    namespace TestWebsocket
    {
        class Program
        {
            static void Main()
            {
                FleckLog.Level = LogLevel.Debug;
                var allSockets = new List<IWebSocketConnection>();
                var server = new WebSocketServer("ws://localhost:8080");
                server.Start(socket =>
                {
                    socket.OnOpen = () =>
                    {
                        Console.WriteLine("Open!");
                        allSockets.Add(socket);
                    };
                    socket.OnClose = () =>
                    {
                        Console.WriteLine("Close!");
                        allSockets.Remove(socket);
                    };
                    socket.OnMessage = message =>
                    {
                        Console.WriteLine(message);
                        allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
                    };
                });
    
                var input = Console.ReadLine();
                while (input != "exit")
                {
                    foreach (var socket in allSockets.ToList())
                    {
                        socket.Send(input);
                    }
                    input = Console.ReadLine();
                }
    
            }
        }
    }
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
        <title>websocket client</title>
        <script type="text/javascript">
            var start = function () {
                var inc = document.getElementById('incomming');
                var wsImpl = window.WebSocket || window.MozWebSocket;
                var form = document.getElementById('sendForm');
                var input = document.getElementById('sendText');
    
                inc.innerHTML += "connecting to server ..<br/>";
    
                // create a new websocket and connect
                window.ws = new wsImpl('ws://localhost:8080/');
    
                // when data is comming from the server, this metod is called
                ws.onmessage = function (evt) {
                    inc.innerHTML += evt.data + '<br/>';
                };
    
                // when the connection is established, this method is called
                ws.onopen = function () {
                    inc.innerHTML += '.. connection open<br/>';
                };
    
                // when the connection is closed, this method is called
                ws.onclose = function () {
                    inc.innerHTML += '.. connection closed<br/>';
                }
    
                form.addEventListener('submit', function(e){
                    e.preventDefault();
                    var val = input.value;
                    ws.send(val);
                    input.value = "";
                });
    
            }
            window.onload = start;
        </script>
    </head>
    <body>
        <form id="sendForm">
            <input id="sendText" placeholder="Text to send" />
        </form>
        <pre id="incomming"></pre>
    </body>
    </html>
    
    // Ruby 1.9
    // gem install em-websocket required.
    require 'em-websocket'
    
    EventMachine::WebSocket.start(:host => "localhost", :port => 8080) do |ws|
      ws.onopen    { ws.send "RS: Hello Client!"}
      ws.onmessage { 
                |msg| ws.send "RS: Pong: #{msg}" 
                puts msg 
               }
      ws.onclose   { puts "WebSocket closed" }
    end
    
    HTTPRequest request(HTTPRequest::HTTP_GET, "/ws", "HTTP/1.1" );