C#网络编程笔记(1) -- TCP Socket通信基本过程和思路时间:2022-01-27 04:00:47客户端通信的基本过程: IPAddress adr = IPAddress.Parse("192.168.1.1"); //设定通信ipIPEndPoint ipe = new IPEndPoint(adr,8090); //把ip绑定到ipe上Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);//建立套接字server.connect(ipe);server.send(buffer);//发送buffer字符if(server.Receive(buffer)>0){ //然后读出buffer的内容}server.Shutdown(SocketShutdown.Both);server.Close(); 服务器端通信的基本过程 IPAddress adr = IPAddress.Any;IPEndPoint ipe = new IPEndPoint(adr,8090);Socket server = new Socket(AddressFamily.InterNetwork, SocketType.stream,ProtocolType.IP);server.Bind(ipe);server.Listen(3);while(true){ if(Socket client = server.Accept()){ client.Receive(buffer);//接受 client.send(buffer);//发送 }} 详细的代码下载:http://download.csdn.net/source/1991388