you should use send() and recv() for tcp connections and sendto() and recvfrom() for udp connections.
Using read() and write() for network sockets is like using a spoon for digging :p

...