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.

48 lines
1.3 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _01_HolaSocketServidor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
Socket miSocketServidor = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint miDireccionEscucha = new IPEndPoint(IPAddress.Any, 2000);
try
{
miSocketServidor.Bind(miDireccionEscucha);
miSocketServidor.Listen(1);
//esta línea es bloqueante
Socket cliente = miSocketServidor.Accept();
Debug.WriteLine("Conexión exitosa del cliente: " +
cliente.RemoteEndPoint.ToString());
cliente.Close();
miSocketServidor.Close();
}
catch (Exception error)
{
Debug.WriteLine("Error: {0}", error.ToString());
}
}
}
}

Powered by Informatica FP.