thiagoralves / OpenPLC_v2

OpenPLC with the new IEC ST to C compiler
http://www.openplcproject.com
GNU General Public License v3.0
189 stars 108 forks source link

Use SO_REUSEADDR and SO_REUSEPORT socket options to fix bind error #1

Closed SkyTrix closed 7 years ago

SkyTrix commented 7 years ago

When uploading a new program to OpenPLC, the openplc binary is killed and restarted. Binding to port 502 fails every time because the kill and respawn happens in quick succession. Manual intervention is therefore constantly needed.

Letting the socket reuse the address and port fixes this error. See: http://stackoverflow.com/a/25193462/239683

SkyTrix commented 7 years ago

I should probably note that I'm running it as a soft PLC on ubuntu in a virtual machine. I experience it every single time.