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; package lab12;
import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
...@@ -22,14 +23,13 @@ public class ServerApp { ...@@ -22,14 +23,13 @@ public class ServerApp {
protected void listen() { protected void listen() {
System.out.println("Server started and ready to connection"); System.out.println("Server started and ready to connection");
try { while (true) {
while (true) { try(Socket socketFromClient = server.accept()) {
Socket socketFromClient = server.accept();
System.out.println("Client connected: " + socketFromClient.getInetAddress()); System.out.println("Client connected: " + socketFromClient.getInetAddress());
new ServerComunicator(socketFromClient).handle(); new ServerComunicator(socketFromClient).handle();
} catch (IOException e) {
e.printStackTrace();
} }
} catch (Exception e) {
e.printStackTrace();
} }
} }
......
...@@ -22,7 +22,7 @@ public class ServerComunicator { ...@@ -22,7 +22,7 @@ public class ServerComunicator {
System.out.println("New thread starteds. Thred ID = " + Thread.currentThread().getId()); System.out.println("New thread starteds. Thred ID = " + Thread.currentThread().getId());
do { do {
lineRededClient = readerFromClentSocket.readLine(); 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("Your text is interesting! Do you like this one? ");
writerToClentSocket.write(lineRededClient.toUpperCase()); writerToClentSocket.write(lineRededClient.toUpperCase());
writerToClentSocket.newLine(); 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