You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

  1. /* Angelehnt an Kurose/Ross Computernetzwerke (bis 5e Java, ab 6e Python) */
  2. package verteiltesysteme.socket.simple;
  3. import java.io.*;
  4. import java.net.*;
  5. class TCPServer {
  6. public static void main(String argv[]) throws Exception {
  7. int tcpPort = 36037;
  8. String clientSentence;
  9. String capitalizedSentence;
  10. // Server-Socket erzeugen
  11. @SuppressWarnings("resource")
  12. ServerSocket welcomeSocket = new ServerSocket(tcpPort);
  13. while (true) {
  14. Socket connectionSocket = welcomeSocket.accept();
  15. BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
  16. DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
  17. // Try/Catch hinzugef�gt, nachdem bei Einsatz Amazon AWS (Healthcheck des ELB) clientSentence null war
  18. try {
  19. clientSentence = inFromClient.readLine();
  20. if (clientSentence != null) {
  21. capitalizedSentence = clientSentence.toUpperCase() + '\n';
  22. outToClient.writeBytes(capitalizedSentence);
  23. }
  24. } catch (IOException ioe) {
  25. ioe.printStackTrace();
  26. }
  27. connectionSocket.close();
  28. }
  29. }
  30. }