Commit bb55e9d7 authored by Jonathan Poalses's avatar Jonathan Poalses

Updated gradle and java version, changed to using executor service, added git ignore

parent bdc81554
### Leiningen ###
/.lein-*
/.nrepl-port
/.prepl-port
### IntelliJ IDEA ###
*.iml
*.ipr
modules.xml
.idea/
cmake-build-*/
*.iws
out/
.idea_modules/
atlassian-ide-plugin.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Java ###
*.class
*.log
*.ctxt
.mtj.tmp/
*.jar
!gradle-wrapper.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
### Mercurial ###
.hgignore
.hg/
### VSCode/Calva ###
.calva/
.clj-kondo/
.lsp/
### Misc ###
/target
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build
/local/*.hprof
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
......@@ -4,6 +4,7 @@ package jonathan.poalses;
import java.io.*;
import java.net.*;
import java.util.concurrent.Executors;
// Server class
public class Server {
......@@ -16,33 +17,32 @@ public class Server {
}
private static void handle(ServerSocket serverSocket) throws IOException {
while (true) {
Socket socket = null;
try (var executor = Executors.newCachedThreadPool()) {
while (true) {
Socket socket = null;
try {
// socket object to receive incoming client requests
socket = serverSocket.accept();
try {
// socket object to receive incoming client requests
socket = serverSocket.accept();
System.out.println("A new client is connected : " + socket);
System.out.println("A new client is connected : " + socket);
// input and output streams
DataInputStream inputStream = new DataInputStream(socket.getInputStream());
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
// input and output streams
DataInputStream inputStream = new DataInputStream(socket.getInputStream());
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
System.out.println("Assigning new thread for this client");
outputStream.writeUTF("{Server} Connection Successful\n");
System.out.println("Assigning new thread for this client");
outputStream.writeUTF("{Server} Connection Successful\n");
// create a new thread object
Thread thread = new Thread(new ServerThread(socket, inputStream, outputStream));
// Create a server thread
executor.submit(new ServerThread(socket, inputStream, outputStream));
// Invoking the start() method
thread.start();
} catch (Exception e) {
if (socket != null) {
socket.close();
} catch (Exception e) {
if (socket != null) {
socket.close();
}
e.printStackTrace();
}
e.printStackTrace();
}
}
}
......
Markdown is supported
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