A Socket Tutorial
The Socket API
import java.io.*;
import java.net.*;
public class httpTest {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int HTTPport=80;
InetAddress ip = InetAddress.getByName("www.umsl.edu");
System.out.println("The Inet address is "+ip+"\n\n");
Socket socket = new Socket(ip, HTTPport);
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.println("GET /~siegelj/littleFile.html HTTP/1.0\n");
String the_response="";
while ((the_response=in.readLine())!=null) {
System.out.println(the_response);
}
}
}
The Output
The Inet address is www.umsl.edu/134.124.1.234
HTTP/1.1 200 OK
Date: Mon, 21 Jul 2014 15:16:51 GMT
Server: Apache
Last-Modified: Mon, 21 Jul 2014 15:12:37 GMT
ETag: "a2c02a-55-898b8340"
Accept-Ranges: bytes
Content-Length: 85
Content-Type: text/html
Connection: close
<html>
<body>
<center>
<h1>Just a Little Test File</h1>
</center>
</body>
</html>