To get rid of Address already in use” error with bind system call, SO_REUSEADDR socket option should be set before invoking bind. This makes operating system to allow the socket to bind if there is no active socket bound to the requested address and port. See code example in Resolve “Address already in use” error with bind article.
http://www.techpulp.com/articles/networking/tip-error-address-already-in-use.php