Ejemplo n.º 1
0
        private void connectBtn_Click(object sender, EventArgs e)
        {
            if (AreMessageBoxesFilledCorrectly())
            {
                tcpServer = new TcpClient();
                try
                {
                    tcpServer.Connect(serverIPBox.Text, Int32.Parse(portBox.Text));

                    FormChatWindow chatWindow = new FormChatWindow(this, tcpServer, nameBox.Text);

                    this.Hide();
                    chatWindow.ShowDialog();
                    //   chatWindow.StartListening();
                }
                catch (SocketException ex)
                {
                    MessageBox.Show("Failed to connect to server");
                }
                // tcpServer.Close();
            }
            else
            {
                MessageBox.Show("Not all fields are filled properly");
            }
        }
Ejemplo n.º 2
0
        public CommandHandler(ServerHandler serverConnection, FormChatWindow chatWindow)
        {
            this.serverConnection              = serverConnection;
            this.chatWindow                    = chatWindow;
            chatWindow.EventClientConnect     += OnEventClientConnect;
            chatWindow.EventClientDisconnect  += OnEventClientDisconnect;
            chatWindow.EventClientSendMessage += OnEvenClientSendMessage;

            serverConnection.EventClientRecieveMessage += OnEventClientRecieveMessage;
        }
Ejemplo n.º 3
0
 public ServerHandler(TcpClient server, FormChatWindow chatWindow)                                                                                         // Establishing connection, listening
 {
     if (server != null)
     {
         try
         {
             SetupListening(server, chatWindow);
         }
         catch (Exception ex)
         { }
     }
 }
Ejemplo n.º 4
0
 private void SetupListening(TcpClient server, FormChatWindow chatWindow)
 {
     this.server = server;
     try
     {
         netStream    = server.GetStream();
         binaryReader = new BinaryReader(netStream, Encoding.UTF8);
         binaryWriter = new BinaryWriter(netStream, Encoding.UTF8);
     }
     catch (IOException ex)
     {
         ex.Data.Add("Description", "Error initializing Binary IO");
         throw ex;
     }
     catch (Exception ex)
     {
         ex.Data.Add("Description", "Unknown error setting up listening for server");
         throw ex;
     }
     // eventSystem = new EventSystem();
     this.chatWindow = chatWindow;
     commandHandler  = new CommandHandler(this, this.chatWindow);
 }