Sockets
In this worksheet, you will begin to explore sockets and network programming.
- What server listens at port 22? What port does HTTP use?
- Open a telnet session to http://www.cnn.com and type GET /
following by return. What happens? What is all that stuff?
- List the 5 pieces of information that make a socket connection
unique? What 3 pieces of information do you need to write code to
make a socket connection to a machine?
- Why would you want to ever connect to a socket on the same machine?
- Write a simple Java client that mimics what you did with telnet
above. It should open a socket to the HTTP port on machine
www.cnn.com and then write "GET /\n" to the machine. Read the
response until the channel is closed.
- Use the java.net.URL object to test whether a URL is valid (i.e.,
type in some good ones and some incorrect ones). It will throw
MalformedURLException if necessary.
- Use java.net.URLConnection to re-implement the simple Java client
above. There are methods like connect() and getContent() that you
will find useful.