You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
37 lines
1.0 KiB
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());
|
|
}
|
|
}
|
|
}
|
|
}
|