//MiniServer.java - Server That Echos What IT Receives server import java.io. *; Import java.net. *;
Class server {public static void main (string args []) throws java.ioException {byte a [] = new byte [10]; if (args.length! = 1) {system.out.println ("Usage: " Java miniServer portnumber"); system.exit (1);} int portnum = integer.parseint (args [0]); serversocket sock = null; try {sock = new serversocket (portnum);} catch (IOException E ) {System.out.println ("You cannot listen to port:" portnum "," E); system.exit (1);} system.out.println ("Listening port" portnum); socket clientsocket = Null; try {clientsocket = sock.accept ();} catch (ioException e) {system.out.println ("Receive failed:" portnum "," e); system.exit (1);} bufferedreader input = New InputStreamReader (ClientSocket.getInputStream ())); PrintWriter Output = New PrintWriter (Clientsocket.getOutputStr EAM ()); system.out.println ("Connection exists."); int i = 0; string line = INPUT.READLINE (); system.in.read (a); string link = new string (a); While (link! = null) {system.out.println (line); i ; Output.println ("line" i ":" link); output.flush (); system.in.read (a) LINK = New string (a);}}}
**************************************************
//Miniclient.java - Simple Client for MiniServer client import java.io. *; Import java.net. *; Class telnet {public static void main (string args []) throws java.io ioException {byte b [] = new byte [10]; if (args.length! = 2) {system.out.println ("Tip:" "Test your program like Telnet 127.0.0.1 8080") ")"); System.exit using Telnet IP Portnum (0);} Socket Sock = NULL; INT portnum = INTEGER.VALUEOF (args [1]). INTVALUE (); try {sock = new socket (args [0], portnum);} catch (ooException e) {system .out.println ("No connection:" args [0] ":" portnum "," e); system.exit (1);} bufferedreader Input = New BufferedReader (New InputStreamReader (Sock.getInputStream )))))); PrintWriter Output = new printwriter (Sock.getOutputStream ()); system.out.println ("Connection has been established"); System.out.Println ("Please enter message" "and press Enter:") System.in.read (b); String line = new string (b); while (line! = Null) {Output.println (line); output.flush (); line = input.rea DLINE (); System.Out.println ("Server Returns:" line); System.out.println ("Please enter message" "and press Enter:"); System.in.Read (b); Line = new string (b);}}}