Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.Scanner;
  4. public class Server{
  5. public static void main(String argv[]) throws Exception
  6. {
  7. /*1.connection*/
  8. ServerSocket serverSocket = new ServerSocket(6789);
  9. Socket connectionSocket = serverSocket.accept();
  10. /*2. reading from the socket using scanner or BufferedReader*/
  11. Scanner scanner = new Scanner(connectionSocket.getInputStream());
  12. //read
  13. String clientSentence = scanner.nextLine();
  14. System.out.println("Received: " + clientSentence);
  15. /*3. modification of the sentence*/
  16. String modifiedSentence =clientSentence.toUpperCase();
  17. /*4. writing in the socket*/
  18. DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
  19. outToClient.writeBytes(modifiedSentence+ 'n');
  20. scanner.close();
  21. connectionSocket.close();}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement