Browse Source

status messages

master
Sebastian Rieger 6 years ago
parent
commit
0c9d694eb3
  1. 2
      VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/TCPClient.java
  2. 4
      VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/TCPServer.java
  3. 2
      VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/UDPClient.java
  4. 3
      VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/UDPServer.java

2
VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/TCPClient.java

@ -18,6 +18,8 @@ class TCPClient {
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
System.out.println("Enter message to sent to the server:");
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();

4
VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/TCPServer.java

@ -15,9 +15,13 @@ class TCPServer {
@SuppressWarnings("resource")
ServerSocket welcomeSocket = new ServerSocket(tcpPort);
System.out.println("TCP Server started. Waiting for incoming requests...");
while (true) {
Socket connectionSocket = welcomeSocket.accept();
System.out.println("Received request from client " + connectionSocket.getInetAddress() + ":" + connectionSocket.getPort() + " generating response...");
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());

2
VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/UDPClient.java

@ -15,6 +15,8 @@ class UDPClient {
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
System.out.println("Enter message to sent to the server:");
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();

3
VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/UDPServer.java

@ -12,6 +12,8 @@ class UDPServer {
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
System.out.println("UDP Server started. Waiting for incoming requests...");
while (true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
@ -20,6 +22,7 @@ class UDPServer {
InetAddress IPAddress = receivePacket.getAddress();
int clientSrcPort = receivePacket.getPort();
System.out.println("Received request from client " + IPAddress + ":" + clientSrcPort + " generating response...");
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();

Loading…
Cancel
Save