using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//IPAddress ip = new IPAddress(new byte[] { 127, 0, 0, 1 });
IPAddress ip = IPAddress.Parse("127.0.0.1");
//IPAddress ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
TcpListener tlistener = new TcpListener(ip, 1433);
tlistener.Start();
Console.WriteLine("服务器监听启动......");
while (true)//看上去是死循环,由于阻塞方法,大部分时间都在等待
{
TcpClient remoteClient = tlistener.AcceptTcpClient();//接收已连接的客户端,阻塞方法
Console.WriteLine("客户端已连接!local:{0}<---Client:{1}", remoteClient.Client.LocalEndPoint, remoteClient.Client.RemoteEndPoint);
}
//ConsoleKey key;
//do
//{
// key = Console.ReadKey(true).Key;
//}
//while (key != ConsoleKey.Q);
}
}
}