ALE.Tcp.WebSocketHandshake.GetHandshake C# (CSharp) Метод

GetHandshake() публичный статический Метод

public static GetHandshake ( Encoding enc, string secKey, string ip, int port, string origin ) : string
enc System.Text.Encoding
secKey string
ip string
port int
origin string
Результат string
        public static string GetHandshake(Encoding enc, string secKey, string ip, int port, string origin)
        {
            var writer = new StringBuilder();
            writer.AppendLine("HTTP/1.1 101 Web Socket Protocol Handshake");
            writer.AppendLine("Upgrade: websocket");
            writer.AppendLine("Connection: Upgrade");
            writer.AppendLine("WebSocket-Origin: " + origin);
            writer.AppendLine("WebSocket-Location: ws://" + ip + ":" + port + "/ale");
            if (!String.IsNullOrEmpty(secKey))
            {
                writer.AppendLine("Sec-WebSocket-Accept: " + HashSecKey(enc, secKey));
            }
            writer.AppendLine("");
            return writer.ToString();
        }

Usage Example

Пример #1
0
        private void SendHandshake(byte[] buffer, int bytesRead)
        {
            string text = Encoding.GetString(buffer, 0, bytesRead);

            ClientHandshake = text;
            string secKey = WebSocketHandshake.GetSecKey(ClientHandshake);

            SendUnencoded(WebSocketHandshake.GetHandshake(Encoding, secKey, Server.IP, Server.Port, Server.Origin),
                          ex =>
            {
                if (ex != null)
                {
                    EventLoop.Pend(() => Server.Callback(ex, null));
                }
                BeginRead();
                EventLoop.Pend(() => Server.Callback(null, this));
            });
        }