COMP 3400 Networks Lecture 4: Application Layer - DNS, P2P, Sockets
major resource: Computer Networking (4th Edition), Kurose and Ross, Addison Wesley, 2008

[ previous | schedule | next ]

Application Layer service: DNS (Domain Name System)

Overview of DNS

DNS network organization

Pure Recursive DNS query

Iterative DNS query

Caching is Critical to DNS Performance

DNS Security and Resilience are Paramount

Alternative Root Servers

Peer-To-Peer (P2P) Applications and Protocols

Intro and Major Issues

Sockets Programming for TCP

Inter-process communication through sockets

Overview of Sockets

Client protocol (typical):

  1. Request socket connection, wait for confirmation
  2. Send request over socket
  3. Wait for and receive server reply over socket
  4. Repeat send-receive cycle (steps 2 and 3) as required by application protocol
  5. Close socket connection

Server protocol (typical):

  1. Create a server socket to handle incoming connection requests
  2. Wait for incoming connection requests
  3. When request arrives, create a connection socket for communication (this leaves server socket free to accept additional connection requests)
  4. Receive client request over connection socket
  5. Send reply to client over connection socket
  6. Repeat receive-send cycle (steps 4 and 5) as required by application protocol
  7. Close connection socket

Simple Example Java client and server

TCPClient.java
import java.io.*; 
import java.net.*; 
class TCPClient { 
    public static void main(String argv[]) throws Exception   { 
        String sentence; 
        String modifiedSentence; 

        BufferedReader inFromUser = 
            new BufferedReader(new InputStreamReader(System.in)); 
        Socket clientSocket = new Socket("PSandersonLT12.otterbein.edu", 6789); 
        DataOutputStream outToServer = 
            new DataOutputStream(clientSocket.getOutputStream()); 
        BufferedReader inFromServer = 
            new BufferedReader(new
            InputStreamReader(clientSocket.getInputStream())); 
        sentence = inFromUser.readLine(); 
        outToServer.writeBytes(sentence + '\n'); 
        modifiedSentence = inFromServer.readLine(); 
        System.out.println("FROM SERVER: " + modifiedSentence); 
        clientSocket.close();         
    } 
} 
TCPServer.java
import java.io.*; 
import java.net.*; 
class TCPServer { 
  public static void main(String argv[]) throws Exception  { 
      String clientSentence; 
      String capitalizedSentence; 
      ServerSocket welcomeSocket = new ServerSocket(6789); 
      while(true) { 
           Socket connectionSocket = welcomeSocket.accept(); 
           BufferedReader inFromClient = 
              new BufferedReader(new
              InputStreamReader(connectionSocket.getInputStream())); 
           DataOutputStream  outToClient = 
              new DataOutputStream(connectionSocket.getOutputStream()); 
           clientSentence = inFromClient.readLine(); 
           capitalizedSentence = clientSentence.toUpperCase() + '\n'; 
           outToClient.writeBytes(capitalizedSentence); 
        } 
    } 
} 

[ COMP 3400 | Peter Sanderson | Math Sciences home page | Otterbein ]

Last updated:
Peter Sanderson (PSanderson@otterbein.edu)