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 ConnectToMainServer(IPEndPoint serverIP)
        {
            try
            {
                client = new TcpClient(ipAsClient);
                client.Connect(serverIP);
                client.Client.ReceiveTimeout = 7000;
                client.Client.SendTimeout    = 7000;

                myStream = new MyStreamIO(client.GetStream());

                myStream.Write("<isFileServer>");
                myStream.GetNEXT();

                while (true)
                {
                    int numberOfFile = ListHolder.Files.Count;

                    myStream.Write("<sendFilesInfo>");
                    myStream.GetNEXT();

                    myStream.Write(numberOfFile);
                    myStream.GetNEXT();

                    foreach (MyFile file in ListHolder.Files)
                    {
                        myStream.Write(file.FileName);
                        myStream.GetNEXT();

                        myStream.Write(file.FileSize);
                        myStream.GetNEXT();

                        myStream.Write(ipAsServer.Address.ToString());
                        myStream.GetNEXT();

                        myStream.Write(ipAsServer.Port);
                        myStream.GetNEXT();
                    }


                    Thread.Sleep(5000);
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "File server error: when working with main server");
            }
        }
Beispiel #3
0
 public ClientHandler(TcpClient client)
 {
     this.Client = client;
     myStream    = new MyStreamIO(client.GetStream());
 }