class server
{
///<summary>
///应用程序的主入口点。
///</summary>
[STAThread]
static void Main(string[]args)
{
//
//TODO:在此处添加代码以启动应用程序
//
int recv;//用于表示客户端发送的信息长度
byte[] data=new byte[1024];//用于缓存客户端所发送的信息,通过socket传递的信息必须为字节数组
IPEndPoint ipep=new IPEndPoint(IPAddress.Any,9050);//本机预使用的IP和端口
Socketnewsock=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
newsock.Bind(ipep);//绑定
newsock.Listen(10);//监听
Console.WriteLine("waitingforaclient");
Socketclient=newsock.Accept();//当有可用的客户端连接尝试时执行,并返回一个新的socket,用于与客户端之间的通信
IPEndPoint clientip=(IPEndPoint) client.RemoteEndPoint;
Console.WriteLine("connectwithclient:"+clientip.Address+"atport:"+clientip.Port);
stringwelcome ="welcomehere!";
data=Encoding.ASCII.GetBytes(welcome);
热门文档