解析数据通信 [英] parsing data communication

查看:72
本文介绍了解析数据通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想对架构和实施提出疑问:

I want to have a question regarding to an architecture and implementation:

例如,我有这个类图:

SocketComm(1)---有----->(1)FirstParser - 有----> (n)单元

SocketComm (1)--- has ----->(1) FirstParser -- has ----> (n) Unit

- SocketComm:是接收数据的TCP / IP套接字服务器

- SocketComm: is a TCP/IP socket server receiving data

- FirstParser:检查此套接字数据属于哪个单位

- FirstParser: is to check this socket data is belonged to which unit

- 单位:解析数据 

- Units: parsing data 

===函数===

在SocketComm中:是一个TCP / IP套接字服务器接收数据并将它们放在FirstParser中的FirstParser.Queue.Add(Newdata)

in SocketComm: is a TCP/IP socket server receiving data and put them in a list FirstParser.Queue.Add(Newdata)

列表中:是一个每1毫秒检查一次的计时器以检查是否存在队列中的任何项目。如果是,那么检查哪个新数据属于哪个单位

in FirstParser: is a timer which ticks every 1 millisecond to check is there any item in the queue. If yes, then check which newdata is belonged to which unit

单位:是一个计时器,每1毫秒计时一次,以开始与设备的通信

in Unit: is a timer which ticks every 1 millisecond to start its communication with the device

 

因此,FirstParser中有一个计时器,Unit类中有多个计时器。

So there is one timer in FirstParser and multiple timers in Unit class.

有人请给我一些建议吗?这个架构以及使用多个计时器来实现的方式?

Would anybody please give me some advices about this architecture and also the way of using number of timers for implementing?



提前谢谢。


Thanks in advance.

推荐答案

我不确定我是否正确理解了您的案例,但我会提出一些解决方案。人们可以考虑使用发布者 - 订阅者模式。该队列将充当发布者和First Parser 作为订阅者和Frist Parser作为出版商,所有单位作为订阅者。当套接字服务器将数据放入队列时,队列会通知First Parser新数据的到达,而新数据的到来将决定哪个单元在行动中摆动并相应地通知相应的单元。这个解决方案
将消除对队列执行ping操作的需要设置时间间隔,当某些数据到达队列时将触发操作。

I am not sure whether I have understood your case correctly but I would propose some solution. One can think of using publisher- subscriber pattern. The queue would act as publisher and First Parser  would act as subscriber and also Frist Parser as a publisher and all Units as subscribers. When socket server puts the data in queue, the queue would notify First Parser about arrival of new data which in turn would decide which Unit to swing in action and notify corresponding Unit accordingly.This solution would eliminate need of pinging the queue with set time intervals and action would be triggered when some data has arrived into the queue.

希望这会有所帮助。


这篇关于解析数据通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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