EndReceive 接受数据的问题
public static void AcceptCallback(IAsyncResult ar)
{
// Signal the main thread to continue.
allDone.Set();
// Get the socket that handles the client request.
Socket listener = (Socket)ar.AsyncState;
Socket handler = listener.EndAccept(ar);
Log("第一步");
// Create the state object.
StateObject state = new StateObject();
state.workSocket = handler;
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReadCallback), state);
}
public static void ReadCallback(IAsyncResult ar)
{
String content = String.Empty;
// Retrieve the state object and the handler socket
// from the asynchronous state object.
StateObject state = (StateObject)ar.AsyncState;
Socket handler = state.workSocket;
try
{
// Read data from the client socket.
int bytesRead = handler.EndReceive(ar);
EndReceive 接收到的数据是是否每次需要达到state.buffer 在去接受呢?还是可以接受一点点用回调再去接受呢 ?????
{
// Signal the main thread to continue.
allDone.Set();
// Get the socket that handles the client request.
Socket listener = (Socket)ar.AsyncState;
Socket handler = listener.EndAccept(ar);
Log("第一步");
// Create the state object.
StateObject state = new StateObject();
state.workSocket = handler;
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReadCallback), state);
}
public static void ReadCallback(IAsyncResult ar)
{
String content = String.Empty;
// Retrieve the state object and the handler socket
// from the asynchronous state object.
StateObject state = (StateObject)ar.AsyncState;
Socket handler = state.workSocket;
try
{
// Read data from the client socket.
int bytesRead = handler.EndReceive(ar);
EndReceive 接收到的数据是是否每次需要达到state.buffer 在去接受呢?还是可以接受一点点用回调再去接受呢 ?????
...全文
相关推荐
C# socket技术的后台文件传输(服务器+客户机)设计实例
C# socket技术的后台文件传输(服务器+客户机)设计实例
TCPListener异步接收数据.zip
做服务端千万别用线程保持连接,到了3000以上就各种连接异常了,下面这种异步接收方法完美解决,保存个上万连接不成问题,对于单独的socket,onbody是顺序执行的,包不会错位
visual C#网络编程(郑阿奇编)同步通信程序的源代码
visual C#网络编程(郑阿奇编)同步通信程序的源代码
C#+Socket异步传输
C#+Socket异步传输 基于TCP 编程
Socket TCPSERVER
C# Socket TCPSERVER 用异步(非阻塞)方式实现TCPSERVER


