Esempio n. 1
0
        protected override void NewConnection(object sender, SocketArgs args)
        {
            try
            {
                string request = string.Format(
                    "GET {0} HTTP/1.1" + Environment.NewLine +
                    "Upgrade: WebSocket" + Environment.NewLine +
                    "Connection: Upgrade" + Environment.NewLine +
                    "Host: {1}" + Environment.NewLine +
                    "Origin: {2}" + Environment.NewLine +
                    "Pragma: no-cache" + Environment.NewLine +
                    "Cache-Control: no-cache" + Environment.NewLine +
                    "Accept-Encoding: gzip, deflate" + Environment.NewLine +
                    "Sec-WebSocket-Version: 13" + Environment.NewLine +
                    "Sec-WebSocket-Key: " + Hybi.GenerateKey() + "" + Environment.NewLine +
                    "Sec-WebSocket-Extensions: permessage-deflate; client_no_context_takeover; server_no_context_takeover" +
                    Environment.NewLine + Environment.NewLine, "/", args.Socket.Endpoint, "null");

                if (!this.SendRaw(MemoryUtils.ToLatin(request)))
                {
                    Console.WriteLine("Sendraw failed?");
                    throw new Exception("Sendraw failed?");
                }
            }
            catch (ObjectDisposedException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
Esempio n. 2
0
        private void SendBytes(byte[] Buffer)
        {
            int  MinCompress = 250;
            bool bCompress   = (Encoder != null);

            if (bCompress && (Buffer.Length <= MinCompress))
            {
                bCompress = false;
            }

#if DEBUG
            bCompress = (Encoder != null);
#endif

            if (bCompress)
            {
                Buffer = Encoder.Compress(Buffer);
            }

            byte[] bHybi = Hybi.HybiEncode(Buffer, bCompress);

            if (!SendRaw(bHybi))
            {
                Console.WriteLine("Sendraw failed?");
                throw new Exception("Sendraw failed?");
            }
        }