In your server code, you have:
if(listenfd = socket(AF_INET,SOCK_STREAM,0) < 0)
The problem is to do with the precedence of C operators. Because the <
comparison has a higher precedence than assignment, your statement will set listenfd
to the boolean value of the x < y
bit meaning, because the socket
will most likely succeed, it will most likely be set to 0 (false), hence standard input (file descriptor 0).
If you must use the C shortcuts (I know they're handy but sometimes they're less readable than the alternatives), you should use the variant:
if ((listenfd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
as you have already done in your client code:
if ((socketfd = socket (AF_INET, SOCK_STREAM, 0)) < 0)