this might not be right but...
I think you''re missing a recv() call somewhere in there
int recv(int sockfd, void *buf, int len, unsigned int flags);
sockfd is socket definition, *buf is where you''re recieving it, len is maximum length *buf can be, and flags I leave as 0.
hope thats right