using System; using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Text; using System.Windows.Forms; namespace _04_SocketClienteDatos { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Button1_Click(object sender, EventArgs e) { Socket miSocketCliente = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint miServidor = new IPEndPoint(IPAddress.Parse(this.textBox1.Text), 2000); try { miSocketCliente.Connect(miServidor); Debug.WriteLine("Conectado con éxito"); //envío de datos byte[] textoEnviar; textoEnviar = Encoding.Default.GetBytes(this.textBox2.Text); miSocketCliente.Send(textoEnviar, 0, textoEnviar.Length, SocketFlags.None); Debug.WriteLine("Texto enviado con éxito"); //cerrar miSocketCliente.Close(); } catch (Exception error) { Debug.WriteLine("Error: " + error.ToString()); } } } }