Download Dynamic C TCP IP 1
Transcript
3.6 UDP Socket Functions (7.05 and later) Starting with Dynamic C 7.05, the UDP implementation is a true record service. It receives distinct datagrams and passes them as such to the user program. The socket I/O functions available for TCP sockets will no longer work for UDP sockets. 3.6.1 Control Functions for UDP Sockets These functions change the status of the socket or its I/O buffer. • udp_close • udp_extopen • udp_open 3.6.2 Status Function for UDP Sockets These functions return useful information about the status of either a socket or its I/O buffers. • • • • • • sock_bytesready sock_dataready sock_rbleft sock_rbsize sock_rbused udp_peek For a UDP socket, sock_bytesready() returns the number of bytes in the next datagram in the socket buffer, or -1 if no datagrams are waiting. Note that a return of 0 is valid, since a datagram can have 0 bytes of data. 3.6.3 I/O Functions for UDP Sockets These functions handle datagram-at-a-time I/O: • • • • udp_recv udp_recvfrom udp_send udp_sendto The write function, udp_sendto(), allows the remote IP address and port number to be specified. The read function, udp_recvfrom(), identifies the IP address and port number of the host that sent the datagram. There is no longer a UDP read function that blocks until data is ready. 42 TCP/IP User’s Manual