Subsections
- Socket
- ServerSocket
- URL
- URLConnection
- Socket socket = new Socket(host, port);
- server is a String or InetAddress.
- UnknownHostException - could not convert the given host/server name to a TCP/IP address.
- IOException - could not find server or port.
- Methods: getInetAddress(), getPort(), getLocalPort(), getLocalAddress(), getInputStream(), getOutputStream().
- Listens for clients.
- Use accept() to accept incoming connections.
- accept returns a Socket.
- Socket socket = serverSocket.accept();
- A new ServerSocket is created on a port using a ServerSocket() constructor.
- ServerSocket listens on the port using the accept() method.
- Uses getInputStream() and/or getOutputStream().
- Server and client interact using an agreed-upon communication protocol.
- Either the server or the client (or both) close the connection.
- The server goes back to listening with the accept() method.
- URL page = new URL("http://www.devdaily.com");
- getContent()
- openStream()
- openConnection() - returns a URLConnection.
|
|