Exemplo n.º 1
0
        private void MakeConnect(IPEndPoint serverIP)
        {
            try
            {
                Listener = new TcpListener(serverIP);
                Listener.Start();


                while (true)
                {
                    TcpClient  client       = Listener.AcceptTcpClient();
                    MyStreamIO myStream     = new MyStreamIO(client.GetStream());
                    string     firstMessage = myStream.ReadString();
                    myStream.SendNEXT();

                    if (firstMessage == "<isFileServer>")
                    {
                        FileServerHandler handler = new FileServerHandler(client);
                        ListHolder.FileServers.Add(handler);
                        handler.Start();
                    }
                    else if (firstMessage == "<isClient>")
                    {
                        ClientHandler handler = new ClientHandler(client);
                        ListHolder.Clients.Add(handler);
                        handler.Start();
                    }

                    ListHolder.UpdateList();
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Main server error: when waiting for connection");
            }
        }
 public FileServerHandler(TcpClient client)
 {
     this.Client = client;
     myStream    = new MyStreamIO(client.GetStream());
 }