Sockets, HTTP and addressing (w1-w2) Flashcards
iPv4 is a __ bit number, written in which format?
Also, what is the range of numbers between each dot? Why?
32 bit number, written as dotted quad, range is up to 255 (including 0) , as 2^8 = 256.
how many addresses available in IPv4?
2^32
IPv6 has how many addresses available?
340 282 366 920 938 463 463 374 607 431 768 211 456
how are IPV6 addresses formatted?
8 Groups of 16 bits each, each group written in hex with a colon separating the groups
getByName is a method part of which class?
InetAddress class
getByName() accomplishes what?
resolves address with DNS name
getHostAddress() does what?
returns string containing IP address
if given the address www.google.com, write a two line program which returns the correct IP address using InetAddress class
InetAddress IP = InetAddress.getByName(www.google.com);
System.out.println(name + “ : “ +
IP.getHostAddress());
write a two line program which returns the host name, when given an IP Address
InetAddress IP =
InetAddress.getByName(addressIP);
System.out.println(address + “ : “ +
IP.getHostName());
write a two line program which connects to a website, given the port and website name`
InetAddress IP =
InetAddress.getByName(“www.wand.net.nz”);
Socket mysocket = new Socket(IP, 443);
Initialize a printwriter, write a line, then close the writer
PrintWriter out = new PrintWriter(mysocket.getOutputStream(), true); out.println("hello world"); out.close();
Initialize a Buffered Reader given a socket object “socket”
InputStreamReader isr = new InputStreamReader(mysocket.getInputStream()); BufferedReader reader = new BufferedReader(isr);
initialize a serversocket on port 1234 and accept a socket connection
ServerSocket server = new ServerSocket(1234); Socket client = server.accept();
What does the InetAddress class deal with
deals with resolving names and addresses
How can we write a server, so that it can accept more than one connection at a time, allowing two clients to simultaniously use the server?
Threads.