Java Networking Programming Overview
Return to the Java Programming Corner.
java.net.Socketconstructor does the
socket()system call, sets up the server's
sockaddr_instructure, and executes the
Reading / Writing Data
select()that allows you to examine a number of files to see which ones are ready for reading or writing.
Pipeencapsulates on threads and the code for copying data in one direction; two instances are used, one to drive each direction of transfer independently of the other.
Writer, partly because some network services are limited to ASCII, but mainly because the
Socketclass was decided on before there were
Writerclasses. You can always create a
OutputStreamusing the conversion classes. The paradigm for the two most common forms is:
BufferedReader is = new BufferedReader ( new InputStreamReader(sock.getInputStream())); PrintWriter os = new PrintWriter(sock.getOutputStream(), true);
DataInputStream is = new DataInputStream(sock.getInputStream()); DataOutputStream os = new DataOutputStream(sock.getOutputStream());
DataInputStream is = new DataInputStream( new BufferedInputStream(sock.getInputStream())); DataOutputStream os = new DataOutputStream( new BufferedOutputStream(sock.getOutputStream()));
InetAddressis mainly used for looking up a host's address name or number.
InetAddressobject represents the Internet address of a given computer or host.
InetAddressobject by calling the static
byNamemethod, passing in either a hostname like wwww.iDevelopment.info or a network address as a String, like "184.108.40.206".