Ejemplo n.º 1
0
        //-----------------------------------------------------------------------------------Connection part
        private async void MenuItemCreate_Click(object sender, RoutedEventArgs e)
        {
            var dlg    = new CreateServerDialog();
            var result = dlg.ShowDialog();

            if (result == null || result.Value == false)
            {
                return;
            }
            btnCreate.IsEnabled  = false;
            btnConnect.IsEnabled = false;
            var localEP = new IPEndPoint(dlg.IPAddress, dlg.Port);

            listener = new TcpListener(localEP);
            listener.Start();
            client = await listener.AcceptTcpClientAsync();

            CreateReceiveTask();
            listener.Stop();
        }
Ejemplo n.º 2
0
        private async void MenuItemConnect_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new CreateServerDialog()
            {
                Title = "Connect to server"
            };
            var result = dlg.ShowDialog();

            if (result == null || result.Value == false)
            {
                return;
            }
            var tcpClient = new TcpClient(AddressFamily.InterNetwork);
            await tcpClient.ConnectAsync(dlg.IPAddress, dlg.Port);

            if (tcpClient.Connected)
            {
                client = tcpClient;
                CreateReceiveTask();
            }
            btnCreate.IsEnabled  = false;
            btnConnect.IsEnabled = false;
        }