1.对TcpListener的异步Accept方法:
AsyncCallback CallBack = new AsyncCallback(curr.ReturnAcceptCallBack);
Server.BeginAcceptTcpClient(CallBack, Server);
public void ReturnAcceptCallBack(IAsyncResult ar)
{
try
{
Console.WriteLine("Star AcceptCallBack");
TcpListener Server = (TcpListener)ar.AsyncState;
TcpClient client = Server.EndAcceptTcpClient(ar);
Console.WriteLine(" AcceptCallBack Finished");
NetworkStream River = client.GetStream();
//直接进行接收
AsyncCallback ReadCallBack = new AsyncCallback(BeginReadProcess);
River.BeginRead(RecvBytes, 0, RecvBytes.Length, ReadCallBack, River);
}
catch(Exception ex)
{
wr.WriteLine("Exception Info:" + ex.Message);
wr.Flush();
throw ex;
}
}
2.对NetworkStream的异步处理
3. 还是要保证,连接的正确关闭,在关闭的连接上不再对该连接上写数据.
4.关于tcplistener tcpclient
TcpClient.Close Method
The Close method marks the instance as disposed and closes the TCP connection. Calling this method will close the Socket and also close the associated NetworkStream that is used to send and receive data if one was created.
NetworkStream Constructor (Socket, FileAccess, Boolean)
5.begin end 分别做什么事情