Network I/O
Writing to a remote object on the Internet is not very different from writing to a file on your local machine. You might want to do this if your program needs to store its data to a file on a machine on your network, or if you were creating a program which displayed information on a monitor connected to another computer on your network.
Network I/O is based on the use of streams created with sockets. Sockets are very useful for client/server applications, peer to peer (P2P), and when making remote procedure calls.
A socket is an object that represents an endpoint for communication between processes communicating across a network. Sockets can work with various protocols, including UDP and TCP/IP. In this section we will create a TCP/IP connection between a server and a client. TCP/IP is a connection-based protocol for network communication. Connection-based means that with TCP/IP, once a connection is made the two processes can talk with one another as if they were connected by a direct phone line.
Tip
Although TCP/IP is designed to talk across a network, you can simulate network communication by running the two processes on the same machine.
It is possible for more than one application on a given computer to be talking to various clients all at the same time (e.g., you might be running a web server and also an FTP server and also a program which provides calculation support). Therefore, each application must have a unique ID so that the client can indicate which application ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access