当前位置:编程学习 > C#/ASP.NET >>

BeginReceive 为什么不执行回调

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) 
        { 
            if (bytesRead > 0)
                {
                    // There  might be more data, so store the data received so far.
                    state.sb.Append(Encoding.ASCII.GetString(
                        state.buffer, 0, bytesRead));
                    // Check for end-of-file tag. If it is not there, read 
                    // more data.
                    content = state.sb.ToString();
                                       state.ShangCiN = state.ShangCiN + bytesRead;
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                        new AsyncCallback(ReadCallback), state);
                }
                else
                {
                    if (state.sb.Length > 1)
                    {
                        byte[] bs = GetBinaryOperation(state.ReceDataBuffer,state.ShangCiN,state.filePath);
                        Send(handler, bs);
                    }
                } --------------------编程问答--------------------


EndReceive  这个写呢没有呀.....

补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,