socketprogramminginc(编辑修改稿)内容摘要:
er the data is received so that client can read it rather than client continuously polling for data. Well that is possible with a little effort. If you read the first part of this article, you already know that the Socket class in the namespace has several methods like Receive and Send which are blocking calls. Besides there are also functions like BeginReceive , BeginSend etc. These are meant for asynchronous IO . For example , there are at least two problems with the blocking Receive: When you call Receive function the call blocks if no data is present, the call blocks till some data arrives. Even if there is data when you made the receive call , you don39。 t know when to call next time. You need to do polling which is not an efficient way. You can argue that one can overe these shortings by multithreading meaning that one can spawn a new thread and let that thread do the polling which then notifies the main thread of the data. This concept could work well, but even if you create a new thread it would require your main thread to share the CPU time with this new thread. Windows operating system (Windows NT /2020 /XP) provide what is called Completion Port IO model for doing overlapped ( asynchronous) IO. The details of IO Completion port are beyond the scope of the current discussion, but to make it simple you can think of IO Completion Ports as the most efficient mechanism for doing asynchronous IO in Windows that is provided by the Operating system. Completion Port model can be applied to any kind of IO including the file read /write and serial munication. The .NET asynchronous socket programming helper class39。 s Socket provides the similar model. BeginReceive .NET framework39。 s Socket class provides BeginReceive method to receive data asynchronously ., in an nonblocking manner The BeginReceive method has following signature: public IAsyncResult BeginReceive( byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state )。 The way BeginReceive function works is that you pass the function a buffer , a callback function (delegate) which will be called whenever data arrives. The last parameter, object, to the BeginReceive can be any class derived from object ( even null ) . When the callback function is called it means that the BeginReceive function pleted which means that the data has arrived. The callback function needs to have the following signature: void AsyncCallback( IAsyncResult ar)。 As you can see the callback returns void and is passed in one parameter , IAsyncResult interface , which contains the status of the asynchronous receive operation. The IAsyncResult interface has several properties. The first parameter AsyncState is an object which is same as the last parameter that you passed to BeginReceive(). The second property is AsyncWaitHandle which we will discuss in a moment. The third property indicates whether the receive was really asynchronous or it finished synchronously. The important thing to follow here is that it not necessary for an asynchronous function to always finish asynchronously it can plete immediately if the data is already present. Next parameter is IsComplete which indicates whether the operation has pleted or not. If you look at the signature of the BeginReceive again you will note that the function also returns IAsyncResult. This is interesting. Just now I said that I will talk about the second peoperty of the IAsyncResult in a moment. Now is that moment. The second parameter is called AsyncWaitHandle. The AsyncWaitHandle is of type WaitHandle, a class defined in the namespace. WaitHandle class encapsulates a Handle (which is a pointer to int or handle ) and provides a way to wait for that handle to bee signaled. The class has several static methods like WaitOne ( which is similar to WaitForSingleObject ) WaitAll ( similar to WaitForMultipleObjects with waitAll true ) , WaitAny etc. Also there are overloads of these functions available with timeouts. Coming back to our discussion of IAsyncResult interface, the handle in AsyncWaitHandle (WaitHandle) is signalled when the receive operation pletes. So if we wait on that handle infinitely we will be able to know when the receive pleted. This means if we pass that WaitHandle to a different thread, the different thread can wait on that handle and can notify us of the fact that the data has arrived and so that we can read the data. So you must be wondering if we use this mechanism why would we us。socketprogramminginc(编辑修改稿)
相关推荐
电参数等条件的相互兼容。 设计方法的研究 SoC 的出现对设计方法也提出了更高的要求。 这主要包括设计软件和设计方法的研究和提高,使设计工程师在设计阶段就能正确地仿真出电路系统的全部功能和真实性能指标。 嵌入式 IP 核设计技术 SoC 是许多嵌入式 IP 核的集成,所以有许多 IP 核亟待研究开发,例如 Controlle、 DSP、Interface、 Bus 及 Memory
),并有按时间顺序抽取的样本统计量数值的描点序列,见图。 图 质量数据与控制图 计量型数据 所确定的控制对象即质量指标应能够定量。 所控制的过程必须具有重复性 ,即表现出统计规律性。 所确定的控制对象的数据应为连续值。 计量型控制图:能反映计量型数据特 征,用来绘制、分析计量型数据的控制图。 计数型数据 控制对象只能定性不能而不能定量。 只有两个取值。 与不良项目有关。 计数型控制图
顾客没有认识到问题的严重性之前会为你的需求开发设置障碍。 因此,问需求-效益问题的最佳时机是:在你通过暗示问题建立起买方难题的严重性后,而又在你描述对策之前。 在每笔生意中,出色的销售人员较之一般销售人员所问的需求 效益问题要多 10倍。 四、 SPIN 销售工具如何设计问题 : 例子 背景问题 (S) 了解买家的背景情况(为 你能提供产品服务)可能的信息来源 :
过回流焊 由贴片机贴装到 PCB 上的元件并未真正焊接在 PCB 上,如果这时用手轻轻在 PCB 上一抹,元件就会掉落下来。 过回流焊的作用就是要使锡膏变为锡点,从而使元件牢牢地焊接在 PCB 上。 回流焊接机的内部采用内循环式加热系统,并分为多个温区。 优化的变流速加热结构能在发热管处产生高速热气流,并在 PCB 处产生低速大流量的高温气流,从而确保元件受热均匀、不移位。
、小于、大于某个值的报文。 在错误帧是否捕获栏,你可以选择当网络上有如下错误时是否捕获。 在保存过滤规则条件按钮“ Profiles”,你可以将你当前设置的过滤规则,进行保存,在捕获主面板中,你可以选择你保存的捕获条件。 任意捕获条件 在 Data Pattern 下,你可以编辑任意捕获条件,如下图: 报文捕获解析 26 添加关系节点模板间关系控制模板编辑增加模板添加排除
应是业界技术领先厂商的产品。 7. 简单易用的管理工具 系统的核心是数据存储,所以存储设备的数据分类和管理功能十分重要。 为了提高系统管理的效率、管理的安全性,存储系统必须有便于使用的存储管理工具,以便让单一系统管理员有能力管理整个企业的存储资源。 (二)系统方案设计 为了最大限度地满足用户需求,我们建 议构建以以色列 SANRAD公司基于 iSCSI技术的虚拟存储管理交换机 VSwitch