示例#1
0
        internal void SocketClientTest()
        {
            AppClient <FileProtocol> appClient = new AppClient <FileProtocol>();

            appClient.Connected += (sender, args) =>
            {
                Console.WriteLine(args);
                FileProtocol protocol = new FileProtocol();
                protocol.FileName = "test.file";
                FileStream fileStream = new FileStream("c:\\aa.file", FileMode.Open);
                byte[]     buffer     = new byte[1024];
                int        offset     = 0;
                do
                {
                    offset          = fileStream.Read(buffer, offset, buffer.Length);
                    protocol.Offset = offset;
                    protocol.Data   = buffer;
                    appClient.Send(protocol);
                } while (offset != 0);
            };
            appClient.Received     += (sender, args) => { Console.WriteLine(args); };
            appClient.Disconnected += (sender, args) => { Console.WriteLine(args); };
            ////appClient.Connect("192.168.0.36", 2001);
            appClient.Connect("127.0.0.1", 8099);
        }
示例#2
0
        static async Task Main(string[] args)
        {
            AppClient client = new AppClient();

            client.OnConnected    += OnConnected;
            client.OnDisconnected += OnDisconnected;

            await client.Connect();

            int count = 0;

            while (true)
            {
                await Task.Delay(400);

                var msg = GetRandomArabicMessage();

                Console.WriteLine($"Sending message {count} ...");

                count++;

                msg.Body = "إذا أردت أن تسقط التفاحة هز الشجرة. أول العلم الصمت، والثاتي حسن الاستماع، والثالث الحفظ، والرباع العمل به، ;";

                await client.SendGroupMessage(msg);
            }
        }
示例#3
0
        public async Task Connect()
        {
            Status = $"Connecting to {AppClient.URL} ...";

            await _client.Connect();

            NotifyConnectionsStatus();
        }