I am currently using the library for some simple distributed application, and for this i wanted it to connect and reconnect automatically when it gets disconnected. For some reason i’m not entirely sure how to implement this as the most obvious tries (by checking the current state etc.) failed.
The only working solution i found was this: http://pastebin.com/bMsAKNpM and the only reason why this works is, because it spamms connections, untill it gets an exception that the connection (made by the previous execution) is already open.
Because of how IP/TCP connections work it is not possible to know before attempting to send data that there is an error. The correct approach is to maintain a connection reference and, if when used, there is an error recreate the connection.
An alternative for this is to always use the GetConnection(ConnectionInfo) method that performs a connection test, which if it fails will reestablish the connection.