Restoring back the posix connect. The problem was not in the socket, but in std::cout trying to send the stuff out. Not sure why but it makes segfault.
Need to investigate further to figure out the reason, however disabling it solves the problem!
Fixed the type of commandACK.
Adding a thread that sends heart-bit in a form of ack command.
A very primitive approach that works sufficiently good for now.