Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Client TCP - Form1.cs

Form1.cs

Caricato da:
Scarica il programma completo

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Net;
  8. using System.Net.Sockets;
  9. using System.Threading;
  10. using System.Text;
  11.  
  12.  
  13.  
  14. namespace WindowsApplication12
  15. {
  16.         /// <summary>
  17.         /// Descrizione di riepilogo per Form1.
  18.         /// </summary>
  19.         public class Form1 : System.Windows.Forms.Form
  20.         {
  21.                 Socket s;
  22.                 private System.Windows.Forms.TextBox i;
  23.                 private System.Windows.Forms.TextBox p;
  24.                 private System.Windows.Forms.TextBox r;
  25.                 private System.Windows.Forms.Button button1;
  26.                 private System.Windows.Forms.Button button3;
  27.                 /// <summary>
  28.                 /// Variabile di progettazione necessaria.
  29.                 /// </summary>
  30.                 private System.ComponentModel.Container components = null;
  31.  
  32.                 public Form1()
  33.                 {
  34.                         //
  35.                         // Necessario per il supporto di Progettazione Windows Form
  36.                         //
  37.                         InitializeComponent();
  38.  
  39.                         //
  40.                         // TODO: aggiungere il codice del costruttore dopo la chiamata a InitializeComponent
  41.                         //
  42.                 }
  43.  
  44.                 /// <summary>
  45.                 /// Pulire le risorse in uso.
  46.                 /// </summary>
  47.                 protected override void Dispose( bool disposing )
  48.                 {
  49.                         if( disposing )
  50.                         {
  51.                                 if (components != null)
  52.                                 {
  53.                                         components.Dispose();
  54.                                 }
  55.                         }
  56.                         base.Dispose( disposing );
  57.                 }
  58.  
  59.                 #region Codice generato da Progettazione Windows Form
  60.                 /// <summary>
  61.                 /// Metodo necessario per il supporto della finestra di progettazione. Non modificare
  62.                 /// il contenuto del metodo con l'editor di codice.
  63.                 /// </summary>
  64.                 private void InitializeComponent()
  65.                 {
  66.                         System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
  67.                         this.i = new System.Windows.Forms.TextBox();
  68.                         this.p = new System.Windows.Forms.TextBox();
  69.                         this.r = new System.Windows.Forms.TextBox();
  70.                         this.button1 = new System.Windows.Forms.Button();
  71.                         this.button3 = new System.Windows.Forms.Button();
  72.                         this.SuspendLayout();
  73.                         //
  74.                         // i
  75.                         //
  76.                         this.i.Font = new System.Drawing.Font("Comic Sans MS", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  77.                         this.i.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
  78.                         this.i.Location = new System.Drawing.Point(8, 16);
  79.                         this.i.Name = "i";
  80.                         this.i.Size = new System.Drawing.Size(120, 24);
  81.                         this.i.TabIndex = 0;
  82.                         this.i.Text = "127.0.0.1";
  83.                         //
  84.                         // p
  85.                         //
  86.                         this.p.Font = new System.Drawing.Font("Comic Sans MS", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  87.                         this.p.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
  88.                         this.p.Location = new System.Drawing.Point(208, 16);
  89.                         this.p.Name = "p";
  90.                         this.p.Size = new System.Drawing.Size(120, 24);
  91.                         this.p.TabIndex = 1;
  92.                         this.p.Text = "411";
  93.                         //
  94.                         // r
  95.                         //
  96.                         this.r.Location = new System.Drawing.Point(8, 104);
  97.                         this.r.Multiline = true;
  98.                         this.r.Name = "r";
  99.                         this.r.Size = new System.Drawing.Size(320, 40);
  100.                         this.r.TabIndex = 2;
  101.                         this.r.Text = "";
  102.                         //
  103.                         // button1
  104.                         //
  105.                         this.button1.Font = new System.Drawing.Font("Comic Sans MS", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  106.                         this.button1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
  107.                         this.button1.Location = new System.Drawing.Point(8, 224);
  108.                         this.button1.Name = "button1";
  109.                         this.button1.Size = new System.Drawing.Size(88, 32);
  110.                         this.button1.TabIndex = 3;
  111.                         this.button1.Text = "CoNNeTTi";
  112.                         this.button1.Click += new System.EventHandler(this.button1_Click);
  113.                         //
  114.                         // button3
  115.                         //
  116.                         this.button3.Font = new System.Drawing.Font("Comic Sans MS", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  117.                         this.button3.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
  118.                         this.button3.Location = new System.Drawing.Point(240, 224);
  119.                         this.button3.Name = "button3";
  120.                         this.button3.Size = new System.Drawing.Size(96, 32);
  121.                         this.button3.TabIndex = 5;
  122.                         this.button3.Text = "DiSCoNNeTTi";
  123.                         this.button3.Click += new System.EventHandler(this.button3_Click);
  124.                         //
  125.                         // Form1
  126.                         //
  127.                         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  128.                         this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
  129.                         this.ClientSize = new System.Drawing.Size(344, 266);
  130.                         this.Controls.Add(this.button3);
  131.                         this.Controls.Add(this.button1);
  132.                         this.Controls.Add(this.r);
  133.                         this.Controls.Add(this.p);
  134.                         this.Controls.Add(this.i);
  135.                         this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  136.                         this.MaximizeBox = false;
  137.                         this.Name = "Form1";
  138.                         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  139.                         this.Text = "            (¯`·.¡†§å†åÑå Á††åÇk 1.2†¡.·´¯)";
  140.                         this.ResumeLayout(false);
  141.  
  142.                 }
  143.                 #endregion
  144.  
  145.                 /// <summary>
  146.                 /// Il punto di ingresso principale dell'applicazione.
  147.                 /// </summary>
  148.                 [STAThread]
  149.                 static void Main()
  150.                 {
  151.                         Application.Run(new Form1());
  152.                 }
  153.  
  154.                 private void button1_Click(object sender, System.EventArgs e)
  155.                 {
  156.                         r.Text="";
  157.                         r.AppendText("***CoNNeSSioNe In CoRSo a: "+i.Text+":"+p.Text+"\n");
  158.                         try
  159.                         {
  160.                                 r.AppendText("***CoNNeSSo\n");
  161.                                 s = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
  162.                                 IPEndPoint iep = new IPEndPoint(IPAddress.Parse(i.Text),Convert.ToInt32(p.Text));
  163.                                 s.Connect(iep);
  164.                         }
  165.                         catch{r.AppendText("***IMPoSSiBiLe CoNNeTTeRSi ALL'HoST!\n");}
  166.  
  167.                 }
  168.  
  169.                 private void button2_Click(object sender, System.EventArgs e)
  170.                 {
  171.                 }
  172.  
  173.  
  174.                 private void button3_Click(object sender, System.EventArgs e)
  175.                 {
  176.                 }
  177.                         public void Disconnetti()
  178.                         {
  179.                                 if(s!=null && s.Connected)
  180.                                         s.Close();
  181.                                 r.AppendText("***DiSCoNNeSSo\n");
  182.                         }
  183.                 }
  184.         }