Beispiel #1
0
        static void Main(string[] args)
        {
            superWebSocketInject();
            WebSocket webSocket = new WebSocket("ws://127.0.0.1:24042");
            webSocket.MessageReceived += WebSocket_MessageReceived;
            webSocket.Error += WebSocket_Error;
            webSocket.Closed += WebSocket_Closed;
            webSocket.DataReceived += WebSocket_DataReceived;
            webSocket.Open();
            DataManager dataManager = new DataManager();

            while (true)
            {
                if (webSocket.State == WebSocketState.Open)
                {
                    break;
                }
                Thread.Sleep(1000);
            }
            Console.WriteLine("Connected...");

            //while (true)
            //{
            //    foreach (byte[] packageData in dataManager.PackageDataList)
            //    {
            //        PutFileRequest request = new PutFileRequest
            //        {
            //            ClientGuid = "4C4FEC96-6478-4D25-BEB8-79A68D074E32",
            //            FileData = packageData,
            //            FilePath = "4C4FEC96-6478-4D25-BEB8-79A68D074E32\\2015_01_31\\17\videos\\001\\v_1_20150131_172530_001.avi",
            //            Position = FilePosition.Head
            //        };

            //        var data = WebSocketBlockWrite.PutFileRequestToByte(request);
            //        webSocket.Send(data, 0, data.Length);

            //        //var binaryData = WebSocketBlockWrite.BinaryFormatter(request);
            //        //webSocket.Send(binaryData, 0, binaryData.Length);

            //        //var sharpBinaryData = WebSocketBlockWrite.SharpBinaryFormatter(request);
            //        //webSocket.Send(sharpBinaryData, 0, sharpBinaryData.Length);

            //        //var protoBufData = WebSocketBlockWrite.ProtoBufBinaryFormatter(request);
            //        //webSocket.Send(protoBufData, 0, protoBufData.Length);

            //        //var req = WebSocketBlockWrite.ProtoBufBinaryFormatter(protoBufData);
            //        //Console.WriteLine(req);

            //        //_autoResetEvent.WaitOne();
            //        Interlocked.Add(ref _sendDataCount, packageData.Length);
            //    }
            //}

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            superWebSocketInject();
            //Console.ReadKey();

            //_blockSize = int.Parse(args[0]);
            WebSocket webSocket = new WebSocket("ws://127.0.0.1:9999");

            webSocket.MessageReceived += WebSocket_MessageReceived;
            webSocket.Open();
            //DataManager dataManager = new DataManager();

            while (true)
            {
                if (webSocket.State == WebSocketState.Open)
                {
                    break;
                }
                Thread.Sleep(1000);
            }
            //Console.WriteLine("block size:{0}", _blockSize);
            Console.WriteLine("Connected...");

            while (true)
            {
                DataManager dataManager = new DataManager();
                foreach (byte[] packageData in dataManager.PackageDataList)
                {
                    var arrayList = new List<ArraySegment<byte>>();
                    var array = new ArraySegment<byte>(packageData);
                    arrayList.Add(array);
                    webSocket.Send(arrayList);
                    _autoResetEvent.WaitOne();
                    Interlocked.Add(ref _sendDataCount, packageData.Length);
                }
            }

            Console.ReadKey();
        }