A quick search using google revealed this link with a short tutorial on socket programming with UDP.
UDP is a packet-oriented protocol, so you have to send whole packets and receive whole packets. You can't try reading a UDP socket line by line like you may do with TCP.