Código
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace Sockets
{
class Program
{
static void Main(string[] args)
{
IPAddress direc = Dns.GetHostEntry("localhost").AddressList[0];
IPEndPoint Ep = new IPEndPoint(direc, 12345);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(Ep);
socket.Listen(100);
Socket handler = socket.Accept();
byte[] bytes = new byte[1024]; // array 1024 (t.byte)
int count;
String data = ""; // datos alm.
do
{
count = handler.Receive(bytes);
data = System.Text.Encoding.ASCII.GetString(bytes, 0, count);
if (data != "exit\n")
{
Console.Write("{0}", data);
}
} while (data != "exit\n");
Console.WriteLine("Conexion finalizada");
byte[] msg = System.Text.Encoding.ASCII.GetBytes("\n\nFinalizada conexion");
handler.Send(msg);
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}
}
}










Autor


En línea







