I am creating socket within a while(1) loop & shutting down socket using shutdown().
Again when it reaches in the beginning of the loop , it is throwing error during bind().
Well normally , we do not use bind in a while loop . I believe you should setup a socket, outside a while loop and call accept in a while loop , accept would return u a new socket handle.
If you only want a single connection and want to use bind inside while , then you should try to check what error does bind returns and try to read what it means in rtcs.h file . You would probably get some clue