⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.cs

📁 Csharp实例编程百例.rar
💻 CS
字号:
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;

public class server
{
	public static void Main()
	{
			IPAddress ipAd=IPAddress.Parse("127.0.0.1");
			TcpListener myList=new TcpListener(ipAd,8001);
			myList.Start();
			Console.WriteLine("start the service at port 8001...");
			Console.WriteLine("local node : "+myList.LocalEndpoint);
			Console.WriteLine("wait for the connection...");

			Socket s=myList.AcceptSocket();
			Console.WriteLine("connection from "+s.RemoteEndPoint);
			byte[] b=new byte[100];
			int k=s.Receive(b);
			Console.WriteLine("have accpeted..");
			for (int i=0;i<k;i++)
			{
				Console.Write(Convert.ToChar(b[i]));
			}
			ASCIIEncoding asen=new ASCIIEncoding();
			s.Send(asen.GetBytes("The string was recieved by the server."));
			Console.WriteLine("\n");
			s.Close();
			myList.Stop();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -