Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tcp reconnect when write failed #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhengzijiana
Copy link

In the function func (mb * tcpTransporter) Send (aduRequest [] byte) (aduResponse [] byte, err error) {...} , if there is an error occur when Write data, it returns directly; Imagine the following scenario: while frequently collecting data from Modbus devices, if the Modbus device is shut down abnormally due to sudden power failure or other reasons after a normal TCP connection, and then immediately restarted; At this point, the TCP connection mb.conn in the code is no longer available and will generate an error message: write: broken pipe, However, mb.com is not immediately reclaimed and set to nil. The system usually takes several hours to reclaim mb.com or manually intervene in the program to reconnect, resulting in a large amount of data being missed in between; So when an error occurs when Write data, mb. close() can be called, set conn nil for the next request to reconnect when mb. connect() is executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant