简体   繁体   中英

Best practices: What's the best way to treat byte protocol

I have a serial communication with a device that has its own protocol, in other words, it has some byte arrays (frames) with some meaning. So, I have been treating it with a lot of default frames in a map to send data to the device and a kind of state machine, a big switch-case block to receive data from the device.

I know this question is subjective but I really would like to receive best practices to implement this relationship. Maybe there are design patterns to do the same.

It all depends on how complex it is. If it's something as hairy as 3270 you certainly need a state machine. If it's a simple byte protocol you don't need anything more complex than a DataInputStream. There's not enough information here to say which.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM