|
|
@ -1,29 +1,36 @@ |
|
|
|
/* Angelehnt an Kurose/Ross Computernetzwerke (bis 5e Java, ab 6e Python) */ |
|
|
|
|
|
|
|
package verteiltesysteme.socket.simple; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.net.*; |
|
|
|
|
|
|
|
class TCPServer { |
|
|
|
public static void main(String argv[]) throws Exception { |
|
|
|
int tcpPort = 36037; |
|
|
|
String clientSentence; |
|
|
|
String capitalizedSentence; |
|
|
|
|
|
|
|
// Server-Socket erzeugen |
|
|
|
@SuppressWarnings("resource") |
|
|
|
ServerSocket welcomeSocket = new ServerSocket(tcpPort); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
Socket connectionSocket = welcomeSocket.accept(); |
|
|
|
|
|
|
|
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); |
|
|
|
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); |
|
|
|
|
|
|
|
clientSentence = inFromClient.readLine(); |
|
|
|
capitalizedSentence = clientSentence.toUpperCase() + '\n'; |
|
|
|
outToClient.writeBytes(capitalizedSentence); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/* Angelehnt an Kurose/Ross Computernetzwerke (bis 5e Java, ab 6e Python) */ |
|
|
|
|
|
|
|
package verteiltesysteme.socket.simple; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.net.*; |
|
|
|
|
|
|
|
class TCPServer { |
|
|
|
public static void main(String argv[]) throws Exception { |
|
|
|
int tcpPort = 36037; |
|
|
|
String clientSentence; |
|
|
|
String capitalizedSentence; |
|
|
|
|
|
|
|
// Server-Socket erzeugen |
|
|
|
@SuppressWarnings("resource") |
|
|
|
ServerSocket welcomeSocket = new ServerSocket(tcpPort); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
Socket connectionSocket = welcomeSocket.accept(); |
|
|
|
|
|
|
|
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); |
|
|
|
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); |
|
|
|
|
|
|
|
// Try/Catch hinzugefügt, nachdem bei Einsatz Amazon AWS (Healthcheck des ELB) clientSentence null war |
|
|
|
try { |
|
|
|
clientSentence = inFromClient.readLine(); |
|
|
|
capitalizedSentence = clientSentence.toUpperCase() + '\n'; |
|
|
|
outToClient.writeBytes(capitalizedSentence); |
|
|
|
} catch (IOException ioe) { |
|
|
|
ioe.printStackTrace(); |
|
|
|
} catch (NullPointerException npe) { |
|
|
|
npe.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |