的NetworkStream,有没有类似的东西DataReceived了的SerialPort? (C#) [英] NetworkStream, is there something similar to DataReceived for a SerialPort? (C#)

查看:180
本文介绍了的NetworkStream,有没有类似的东西DataReceived了的SerialPort? (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我有点困惑,为什么我找不到这样的任何地方,或者如果它不存在,那么为什么微软没有实现它?

Ok, so I'm a little confused as to why I can't find this anywhere, or if it doesn't exist then why have Microsoft not implemented it?

因此​​,这里是我的情况,我有一个的NetworkStream,其中有一个可爱的小布尔叫DataAvailable,而我需要的是一个事件,即跳出,并说:嘿,有数据可供你! (因为我懒,我宁愿被告知,可用比有数据不断地问好了,有没有什么数据?一遍又一遍,直到我得到的回应其实,这个时候有)。

So here's my scenario, I have a NetworkStream, which has a lovely little boolean called DataAvailable, and what I need is an event, that jumps out and says "Hey, there's data available for you!" (because I'm lazy and I'd rather be told that there's data available than to keep asking "Alright, is there any data available?" over and over again until I get the response "Actually, this time there is").

类似的东西一的SerialPort(其中有一个很好的事件(DataReceived),是好心告诉我说,数据从该端口接收)本来不错。但我使用一个Socket用的NetworkStream。

Something similar a SerialPort (which has a nice event (DataReceived), that kindly informs me that data is being received from the port) would have been nice. But I'm using a Socket with a NetworkStream.

指明了正确的方向,如果有什么东西blatently明显,我很想念,但如果没有,这是否意味着我将不得不使用一些数据绑定在DataAvailable属性,当它被设置为true,叫我自己的'国产'事件/功能?如果这将是你的方式可以请给我一个小例子来让球滚动?

Point me in the correct direction if there's something blatently obvious that I'm missing, but if not, does this mean I am going to have to use some Data Binding on the DataAvailable property, and when it is set to true, to call my own 'home made' event/function? If this is going to be the way could you please give me a small example to get the ball rolling?

修改
我的完美的答案将是有人来陪伴和向我解释如何我能找到/创造一些非常相似的一个的SerialPort使用DataReceived事件检索,但实施了在以流通过的NetworkStream一个Socket!

Edit
My perfect answer would be for someone to come along and explain to me how I can find/create something extremely similar to the DataReceived Event used with a SerialPort, but implemented for a Socket that is streaming via a NetworkStream!

在此先感谢再次,AP preciated。

Thanks in advance again, appreciated.

推荐答案

有在的NetworkStream 类(的请参阅MSDN )。 的NetworkStream 继承,因此它遵循流模型,它不是基于事件。如果你需要异步接收数据,使用的BeginRead 方法

There are no events in the NetworkStream class (see MSDN). NetworkStream inherits from Stream, therefore it follows the stream model, which is not based on events. If you need to receive data asynchronously, use the BeginRead method

这篇关于的NetworkStream,有没有类似的东西DataReceived了的SerialPort? (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆