.net socket 异步回调 接受 如何解决网速慢???

本文探讨了在网络接收过程中遇到的速度慢问题,并通过调整缓冲区大小及优化接收流程来提高数据接收效率。针对异常情况提供了错误处理机制,确保数据接收过程的稳定性。

从以下代码中,解决网速慢还是不行?

 

 #region ★★  ReceiveObj 状态类
public class ReceiveObj
  {
   public System.Net.Sockets.Socket  socket = null;
            public const int nBufferSize = 4000000;
                                         
            public byte[] bytesBuffer = new byte[nBufferSize];
            public int offet = 0;
          
        }
 #endregion 状态类

 

 private  void  ReceiveCallback(IAsyncResult ar)
  {
   try
   {
                ReceiveObj receiveObj = ar.AsyncState as ReceiveObj;
                System.Net.Sockets.Socket socket = receiveObj.socket;

                int bytesRead = socket.EndReceive(ar);
                if (bytesRead > 0)
                {
                    receiveObj.offet += bytesRead;   解决网速慢?
                    Common.BusinessTransByte btb = new Common.BusinessTransByte();
                    Common.BusinessTrans businessTrans = new Common.BusinessTrans();
                    try
                    {
                        businessTrans = btb.ByteToBusinessTrans(receiveObj.bytesBuffer);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();

                        socket.BeginReceive(receiveObj.bytesBuffer, receiveObj.offet
                           , receiveObj.bytesBuffer.Length - receiveObj.offet, SocketFlags.None
                           , new AsyncCallback(ReceiveCallback), receiveObj);     解决网速慢?

                        return;
                    }

                    try
                    {
                        receiveObj.offet = 0;

                        ReceiveService handler = EventReceiveService; //TO ClientProxy Client socketClient_EventReceiveService
                        if (handler != null)
                        {
                            handler(businessTrans);
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                    finally
                    {

                        socket.BeginReceive(receiveObj.bytesBuffer, receiveObj.offet, receiveObj.bytesBuffer.Length, SocketFlags.None,
                            new AsyncCallback(ReceiveCallback), receiveObj);
                    }
                }
                else
                {
                    ReceiveServiceStop handler = EventReceiveServiceStop;
                    if (handler != null)
                    {
                        handler();
                    }

                }
   
   }
   catch(Exception ex)
            {
                Log.Writer.Debug("ClientProxy SocketClient ReceiveCallback", ex);   
              
            }
        }

来自MIT大佬Natalie Enright Jerger、Tushar Krishna、以及Li-Shiuan Peh总结的体系结构片上网络(onchip network)的学习材料(目前主要用于MIT相关课程教学)。 英文摘要:This book targets engineers and researchers familiar with basic computer architecture concepts who are interested in learning about on-chip networks. This work is designed to be a short synthesis of the most critical concepts in on-chip network design. It is a resource for both understanding on-chip network basics and for providing an overview of state of-the-art research in on-chip networks. We believe that an overview that teaches both fundamental concepts and highlights state-of-the-art designs will be of great value to both graduate students and industry engineers. While not an exhaustive text, we hope to illuminate fundamental concepts for the reader as well as identify trends and gaps in on-chip network research. With the rapid advances in this field, we felt it was timely to update and review the state of the art in this second edition. We introduce two new chapters at the end of the book. We have updated the latest research of the past years throughout the book and also expanded our coverage of fundamental concepts to include several research ideas that have now made their way into products and, in our opinion, should be textbook concepts that all on-chip network practitioners should know. For example, these fundamental concepts include message passing, multicast routing, and bubble flow control schemes. Table of Contents: Preface / Acknowledgments / Introduction / Interface with System Architecture / Topology / Routing / Flow Control / Router Microarchitecture / Modeling and Evaluation / Case Studies / Conclusions / References / Authors' Biographies 是学习NOC等领域的非常好的材料。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值