package ns.Server;

import java.net.Socket;
import java.lang.Runnable;

public class Connection implements Runnable {

    private Socket sock;

    public Connection(Socket sock) {
        this.sock = sock;
    }

    public void run() {
        //
        System.out.println("Socket connected");
    }

}

@@ -29,273 +29,2441 @@
 ava.
-net.Socket;%0Aimport java.lang.Runnable;%0A%0Apublic class Connection implements Runnable %7B%0A%0A    private Socket sock;%0A%0A    public Connection(Socket sock) %7B%0A        this.sock = sock;%0A    %7D%0A%0A    public void run() %7B%0A        //%0A        System.out.println(%22Socket connected%22);
+io.BufferedReader;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.io.IOException;%0Aimport java.io.OutputStream;%0Aimport java.net.InetAddress;%0Aimport java.net.Socket;%0Aimport java.net.UnknownHostException;%0Aimport java.lang.Runnable;%0A%0Apublic class Connection implements Runnable %7B%0A%0A    /**%0A     * The underlying socket connection.%0A     */%0A    private Socket sock;%0A%0A    /**%0A     * Create a new connection handling thread.%0A     *%0A     * @param sock Socket connection to handle.%0A     */%0A    public Connection(Socket sock) %7B%0A        this.sock = sock;%0A    %7D%0A%0A    /**%0A     * Write a string to the socket.%0A     *%0A     * @param data%0A     * @return void%0A     */%0A    protected void write(String data) throws IOException %7B%0A        OutputStream response = this.sock.getOutputStream();%0A        response.write(data.getBytes());%0A    %7D%0A%0A    /**%0A     * Write a string to the socket, and close the connection.%0A     *%0A     * @param data%0A     * @return void%0A     */%0A    protected void end(String data) throws IOException %7B%0A        this.write(data);%0A        this.sock.close();%0A    %7D%0A%0A    /**%0A     * Read all possible input, i.e. a single domain name.%0A     *%0A     * @return The domain name to resolve.%0A     */%0A    protected String readDomain() throws IOException %7B%0A        InputStream input = this.sock.getInputStream();%0A        BufferedReader reader = new BufferedReader(new InputStreamReader(input));%0A        String domain = reader.readLine();%0A        this.sock.shutdownInput();%0A        return domain;%0A    %7D%0A%0A    /**%0A     * Resolve a domain name to an IP address.%0A     *%0A     * @param domain%0A     * @return The IP address.%0A     */%0A    public String resolve(String domain) throws UnknownHostException %7B%0A        InetAddress hostAddress = InetAddress.getByName(domain);%0A        return hostAddress.getHostAddress();%0A    %7D%0A%0A    /**%0A     * Handle a single domain name resolution request.%0A     */%0A    public void handle() throws IOException %7B%0A        String domain = this.readDomain();%0A        try %7B%0A            String ip = this.resolve(domain);%0A            this.end(ip + %22%5Cn%22);%0A        %7D catch (UnknownHostException e) %7B%0A            this.end(%22Unable to resolve host %22 + domain + %22%5Cn%22);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Run the thread: Handle the request.%0A     */%0A    public void run() %7B%0A        try %7B%0A            this.handle();%0A        %7D catch (IOException e) %7B%0A            System.out.println(%22Socket error: %22 + e.getMessage());%0A        %7D
 %0A   

implement domain name resolution & connection thread