12.07.2015 Views

z/VM: TCP/IP Programmer's Reference - z/VM - IBM

z/VM: TCP/IP Programmer's Reference - z/VM - IBM

z/VM: TCP/IP Programmer's Reference - z/VM - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C Sockets Application Program InterfaceA Typical UDP Socket SessionUDP socket processes, unlike <strong>TCP</strong> socket processes, are not clearly distinguishedby server and client roles. Instead, the distinction is between connected andunconnected sockets. An unconnected socket can be used to communicate with anyhost; however, a connected socket, because it has a dedicated destination, can senddata to, and receive data from, only one host.Both connected and unconnected sockets send their data over the network withoutverification. Consequently, once a packet has been accepted by the UDP interface,the arrival of the packet and the integrity of the packet cannot be guaranteed.For the general sequence of calls to be followed for most socket routines usingUDP sockets, see Figure 13.CLIENTSERVER┌─────────────────────────────────────────────────┐┌────────────────────────────────────────────────┐│ │ │ ││ Create a datagram socket s with the socket() │ │ Create a datagram socket s with the socket() ││ call. │ │ call. ││ │ │ │└───────────────────────┬─────────────────────────┘└──────────────────────┬─────────────────────────┘││┌───────────────────────┴─────────────────────────┐│ │ (Optional)│ Bind socket s to a local address with the │ Bind socket s to a local address with the│ bind() call. │ bind() call.││└───────────────────────┬─────────────────────────┘││(Optional)Connect socket s using the connect() call toassociate s with the client address.(Optional)Connect socket s using the connect() call toassociate s with the server address.││┌───────────────────────┴─────────────────────────┐┌──────────────────────┴─────────────────────────┐│ Send and receive data on socket s, using the │ │ Send and receive data on socket s, using the ││ sendto() and recvfrom() calls, until all data │ ───────► │ sendto() and recvfrom() calls, until all data ││ has been exchanged. Use the send() and recv() │ ◄─────── │ has been exchanged. Use the send() and recv()││ calls if connect() was called. │ │ calls if connect() was called. │└───────────────────────┬─────────────────────────┘└──────────────────────┬─────────────────────────┘││┌───────────────────────┴─────────────────────────┐┌──────────────────────┴─────────────────────────┐│ │ │ ││ Close socket s and end the session with the │ │ Close socket s and end the session with the ││ close() call. │ │ close() call. ││ │ │ │└─────────────────────────────────────────────────┘└────────────────────────────────────────────────┘Figure 13. A Typical UDP Socket SessionC Socket LibraryTo use the socket routines described in this chapter, you must have the followingheader files available on your system:v bsdtypes.hv fcntl.hv if.hv in.h16 z/<strong>VM</strong>: <strong>TCP</strong>/<strong>IP</strong> Programmer’s <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!