Socket improvement

Check if the socket connection is ready before sending a message. If it is not ready it waits 300ms (maybe too much?) before trying again.