コード例 #1
0
ファイル: MainForm.cs プロジェクト: mezba1/P2PSimpleChat
 private void button2_Click(object sender, EventArgs e)
 {
     if (this.button2.Text == "Disconnect")
     {
         this.ClientDisconnectClickAction();
     }
     // connect to peer button click
     if (P2PSimpleChat.BLL.Utility.IsValidIPv4(this.textBox3.Text) && P2PSimpleChat.BLL.Utility.IsNumeric(this.textBox4.Text))
     {
         if (this.server == null)
         {
             MessageBox.Show("You must start your peer first before connecting to another peer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             try
             {
                 this.ClientConnectClickAction();
             }
             catch (Exception ex)
             {
                 this.client           = null;
                 this.label7.Text      = "Failure! " + ex.Message;
                 this.label7.ForeColor = System.Drawing.Color.Red;
             }
         }
     }
     else
     {
         MessageBox.Show("Invalid ip address or port number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: mezba1/P2PSimpleChat
 private void ClientDisconnectClickAction()
 {
     this.server.CloseClient();
     this.client.Close();
     this.client = null;
     this.ResetTargetPeerFields();
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: mezba1/P2PSimpleChat
 private void ClientRequestReceivedAction(byte[] data)
 {
     //MessageBox.Show("New request");
     if (this.client == null)
     {
         try
         {
             byte[] d = new byte[data.Length - 3];
             Array.Copy(data, 3, d, 0, d.Length);
             string[] s = Encoding.ASCII.GetString(d).Split(':');
             this.client            = P2PSimpleChat.BLL.Client.GetClientObject(s[0], s[1]);
             this.textBox3.Text     = s[0];
             this.textBox4.Text     = s[1];
             this.groupBox2.Enabled = true;
             this.label7.Text       = "Connected to peer successfully!";
         }
         catch (Exception ex)
         {
             this.client            = null;
             this.groupBox2.Enabled = true;
             this.label7.Text       = "Error occured! " + ex.Message;
             this.label7.ForeColor  = System.Drawing.Color.Red;
         }
     }
 }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: mezba1/P2PSimpleChat
 private void ClientConnectClickAction()
 {
     this.client = P2PSimpleChat.BLL.Client.GetClientObject(textBox3.Text, textBox4.Text);
     this.client.SendRequest(this.textBox1.Text, this.textBox2.Text);
     this.label7.Text      = "Connected to peer successfully!";
     this.label7.ForeColor = System.Drawing.Color.Green;
     this.textBox3.Enabled = false;
     this.textBox4.Enabled = false;
     this.button2.Text     = "Disconnect";
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: mezba1/P2PSimpleChat
 private void ClientDisconnectAction()
 {
     this.AppendText("*** " + textBox3.Text + ":" + textBox4.Text + " disconnected***", System.Drawing.Color.Red, true);
     this.groupBox2.Enabled = true;
     this.textBox3.Text     = "";
     this.textBox4.Text     = "";
     this.textBox3.Enabled  = true;
     this.textBox4.Enabled  = true;
     this.button2.Text      = "Connect";
     try
     {
         this.client.Close();
     }
     catch
     {
     }
     this.client = null;
 }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: mezba1/P2PSimpleChat
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.button1.Text == "Stop")
     {
         this.server.Stop();
         System.Threading.Thread.Sleep(200);
         try
         {
             this.client.Close();
         }
         catch
         {
         }
         this.server = null;
         this.client = null;
         this.ResetPeerFields();
         return;
     }
     // peer start button click
     if (P2PSimpleChat.BLL.Utility.IsValidIPv4(this.textBox1.Text) && P2PSimpleChat.BLL.Utility.IsNumeric(this.textBox2.Text))
     {
         this.server = new P2PSimpleChat.BLL.Server(textBox1.Text, textBox2.Text);
         System.Threading.Thread.Sleep(200);
         if (P2PSimpleChat.BLL.Server.ServerStartedSuccessfully)
         {
             //this.label7.Text = "Success!";
             //this.groupBox1.Enabled = false;
             this.button1.Text          = "Stop";
             server.ClientDataReceived += Server_ClientDataReceived;
             this.label7.Text           = "Peer started successfully!";
             this.label7.ForeColor      = System.Drawing.Color.Green;
         }
         else
         {
             this.AppendText("*** Error: " + P2PSimpleChat.BLL.Server.ErrorMessage + " ***", System.Drawing.Color.Red, true);
             this.server            = null;
             this.groupBox1.Enabled = true;
         }
     }
     else
     {
         MessageBox.Show("Invalid ip address or port number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }