Beispiel #1
0
        public void Stop()
        {
            lock (locker)
            {
                try
                {
                    myStream?.Stop();
                    myStream = null;

                    udpListener?.Close();
                    udpListener = null;

                    Client?.Close();
                    Client = null;

                    workWithClientThread?.Abort();
                    workWithClientThread = null;

                    MyDispatcher.Dispatcher.Invoke(() =>
                    {
                        ListHolder.Clients.Remove(this);
                        ListHolder.UpdateList();
                    });
                }
                catch (Exception)
                {
                }
            }
        }
        private void ListenClientRequest()
        {
            listener = new TcpListener(ipAsServer);
            listener.Start();

            try
            {
                while (true)
                {
                    TcpClient     client = listener.AcceptTcpClient();
                    ClientHandler handle = new ClientHandler(client);
                    ListHolder.Clients.Add(handle);
                    ListHolder.UpdateList();
                    handle.Start();
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "File server error: when waiting for client connection");
            }
        }