/* ------------------------------------------------------ TCP/IP programming exercise; By: Rodelio P. Barcenas ------------------------------------------------------- The program below is a TCP/IP server waiting for client connection. How to run the program; On Stand-Alone PCs; 1. execute the program JAVA myServer 2. Open a telnet session to connect to the TCP/IP server 3. Enter a hostname "localhost" and port "2000" 4. A login menu should appear. 5. Enter a password. 6. The server will display the password you have entered 7. Since the program is incomplete, connection will be closed. On Networked PCs; 1. execute the program JAVA myServer 2. Open a telnet session to connect to the TCP/IP server 3. Replace hostname with IP address and port "2000" 4. A login menu should appear. 5. Enter a password. 6. The server will display the password you have entered 7. Since the program is incomplete, connection will be closed. REQUIREMENT: Create a JAVA client program which will connect to the JAVA TCP/IP server without using telnet session; REFERENCES: http://www.pinoytechzone.com -> Java Examplets -> read java.net examples */ import java.net.*; import java.io.*; public class myServer{ public static void main(String[] arg){ try { int port = 2000; ServerSocket srv = new ServerSocket(port); System.out.println("waiting for connection"); Socket socket = srv.accept(); BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintStream out = new PrintStream(socket.getOutputStream()); out.println("*****************************"); out.println(" Welcome to myJAVA Server"); out.println("*****************************"); out.println(); out.print(" Enter Password: "); out.flush(); String s = rd.readLine(); out.println(); out.println(); out.println(); out.println("Password: "+s); out.flush(); rd.close(); out.close(); } catch(IOException e) { System.out.println("Connection Failed: "+e); } } }