Skip to content
Snippets Groups Projects
Commit 73f06a34 authored by koz01's avatar koz01
Browse files

Close socket, fix word thread.

parent 17cfe804
No related merge requests found
package lab12;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
......@@ -22,14 +23,13 @@ public class ServerApp {
protected void listen() {
System.out.println("Server started and ready to connection");
try {
while (true) {
Socket socketFromClient = server.accept();
while (true) {
try(Socket socketFromClient = server.accept()) {
System.out.println("Client connected: " + socketFromClient.getInetAddress());
new ServerComunicator(socketFromClient).handle();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
......
......@@ -22,7 +22,7 @@ public class ServerComunicator {
System.out.println("New thread starteds. Thred ID = " + Thread.currentThread().getId());
do {
lineRededClient = readerFromClentSocket.readLine();
System.out.println("Thred ID = " + Thread.currentThread().getId() + " readed from client: " + lineRededClient);
System.out.println("Thread ID = " + Thread.currentThread().getId() + " readed from client: " + lineRededClient);
writerToClentSocket.write("Your text is interesting! Do you like this one? ");
writerToClentSocket.write(lineRededClient.toUpperCase());
writerToClentSocket.newLine();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment