/* * A a server that takes a string from the client and returned in upper case is discussed. * Hope this will give an overall picture about how socket programming work. * Available at : http://www.tutebox.com * Thank you for following Tutebox. */ 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()); System.out.println("Server waiting for data..."); clientSentence = inFromClient.readLine(); System.out.println("Recived from client : " + clientSentence); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); } } }