Skip to content
Snippets Groups Projects
Verified Commit 7e274a11 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Initial

parents
No related merge requests found
Pipeline #71 failed with stages
/target/
.settings/
.project
.classpath
.DS_Store
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.jezek</groupId>
<artifactId>lab12</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package lab12;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerApp {
ServerSocket server;
public static void main(String[] args) {
new ServerApp().run();
}
public void run() {
try {
server = new ServerSocket(9460, 5);
listen();
} catch (Exception e) {
// ...
}
}
protected void listen() {
try {
while (true) {
Socket socketFromClient = server.accept();
new Thread(new ServerComunicator(socketFromClient)).start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package lab12;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
public class ServerComunicator implements Runnable{
private Socket socket;
public ServerComunicator(Socket socketFromCliernt) {
this.socket = socketFromCliernt;
}
@Override
public void run() {
try (BufferedReader readerFromClentSocket = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter writerToClentSocket = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()))) {
String lineRededClient;
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);
writerToClentSocket.write("Your text is interesting! Do you like this one? ");
writerToClentSocket.write(lineRededClient.toUpperCase());
writerToClentSocket.newLine();
writerToClentSocket.flush();
} while(!"quit".equals(lineRededClient));
writerToClentSocket.write("May the Java be with you.");
writerToClentSocket.newLine();
writerToClentSocket.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
module cz.jezek.lab12 {
opens lab12 to javafx.fxml;
exports lab12;
}
\ No newline at end of file
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
\ No newline at end of file
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