public void Disconnection()
 {
     _client.Send(new SocketPackage()
     {
         Action = SocketPackage.EnumAction.ClientSignout,
         Data   = _user.Account
     });
     _client.Disonnect();
     pnlFrame.Navigate(new PageSignin());
 }
Esempio n. 2
0
        private void btGui_Click(object sender, EventArgs e)
        {
            String serverIP   = "127.0.0.1";
            int    serverPort = 11000;

            // Kiem tra du lieu dau vao
            String data = tbNoiDung.Text;

            if (String.IsNullOrEmpty(data))
            {
                return;
            }
            SocketClient client = new SocketClient();

            client.IP   = serverIP;
            client.Port = serverPort;
            client.Data = data;
            String msg = client.Send();

            tbLichSu.Text += "Send: " + data + "\r\n";
            if (msg.Equals("OK"))
            {
                String result = client.Result;

                // Hien thi ket qua len lich su tin nhan
                tbLichSu.Text += "[Đã nhận]\r\n";
                tbNoiDung.Text = "";
                tbNoiDung.Focus();
            }
            else
            {
                tbLichSu.Text += "[Lỗi kết nối]\r\n";
            }
        }
Esempio n. 3
0
        static public Task <bool> Echo(SocketClient <CommandLineMessage> client, string context)
        {
            var source = new TaskCompletionSource <bool>();
            var guid   = Guid.NewGuid().ToString();

            client.Send(client.NewRequest("message", Encoding.UTF8.GetBytes("echo" + guid + System.Environment.NewLine), 3000,
                                          ex => source.TrySetException(ex),
                                          message => source.TrySetResult(message.Parameters[0] == guid)));
            return(source.Task);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please specify a port number");
            }

            String port = args[0];

            socketClient.Connect(port);

            while (true)
            {
                string msg_string = Console.ReadLine();
                socketClient.Send(msg_string);
            }
        }
Esempio n. 5
0
        private static void Socket(StudentServiceProvider studentService)
        {
            var ip           = Dns.GetHostEntry("localhost").AddressList[0];
            var port         = 11000;
            var socketClient = new SocketClient(ip, port);

            foreach (List <StudentsAllData> data in studentService.GetAll(2))
            {
                var jsonData = JsonConvert.SerializeObject(data);

                socketClient.Send(jsonData);

                Console.WriteLine($"Отправленные данные:");
                Console.WriteLine(jsonData);
                Console.WriteLine();
                Console.WriteLine("Нажмите любую клавишу для отправки следующего пакета данных...");
                Console.ReadKey();
                Console.WriteLine();
            }
            Console.WriteLine();
        }
Esempio n. 6
0
        private static void Socket(TodoServiceProvider todoService)
        {
            //var ip = new IPAddress(new byte[] { 192, 168, 1, 43 });
            var ip           = Dns.GetHostEntry("localhost").AddressList[0];
            var port         = 11000;
            var socketClient = new SocketClient(ip, port);

            Console.WriteLine("----------------------Сокеты----------------------");
            int slicesCount = 0;

            foreach (List <TodoService> data in todoService.GetAll(2))
            {
                var jsonData = JsonConvert.SerializeObject(data);

                socketClient.Send(jsonData);

                Console.WriteLine($"-----Данные отправлены ({slicesCount++}):");
                Console.WriteLine(jsonData);
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
        }