代码如下 | 复制代码 |
Server using System.Collections.Generic; namespace SocketTest serverSk.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8596)); SocketAsyncEventArgs AcceptSAE = new SocketAsyncEventArgs(); Console.ReadLine(); static void AcceptSAE_Completed(object sender, SocketAsyncEventArgs e) SocketAsyncEventArgs RecieveSAE = new SocketAsyncEventArgs(); serverSk.ReceiveAsync(RecieveSAE);
// sk.DisconnectAsync();//你看看 该怎么做呢? static void SendSAE_Completed(object sender, SocketAsyncEventArgs e) byte[] data = e.Buffer; //重视这里,如何取接洽关系到套接字的发送接管的缓冲区中的值。
|
2 客户端代码
代码如下 | 复制代码 |
Cilent using System.Collections.Generic; namespace SocketTestTwo SocketAsyncEventArgs ConnectSAE = new SocketAsyncEventArgs(); static void ConnectSAE_Completed(object sender, SocketAsyncEventArgs e) SocketAsyncEventArgs RecieveSAE = new SocketAsyncEventArgs(); //先调用异步接管,再调用异步发送。让你体验到异步明显非一般的感触感染。 static void RecieveSAE_Completed(object sender, SocketAsyncEventArgs e) //sk.DisconnectAsync();//你看看 该怎么做呢? static void SendSAE_Completed(object sender, SocketAsyncEventArgs e) |
3 调试运行
先调试运行办事器项目