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 distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
...@@ -4,6 +4,7 @@ package jonathan.poalses; ...@@ -4,6 +4,7 @@ package jonathan.poalses;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.util.concurrent.Executors;
// Server class // Server class
public class Server { public class Server {
...@@ -16,33 +17,32 @@ public class Server { ...@@ -16,33 +17,32 @@ public class Server {
} }
private static void handle(ServerSocket serverSocket) throws IOException { private static void handle(ServerSocket serverSocket) throws IOException {
while (true) { try (var executor = Executors.newCachedThreadPool()) {
Socket socket = null; while (true) {
Socket socket = null;
try { try {
// socket object to receive incoming client requests // socket object to receive incoming client requests
socket = serverSocket.accept(); 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 // input and output streams
DataInputStream inputStream = new DataInputStream(socket.getInputStream()); DataInputStream inputStream = new DataInputStream(socket.getInputStream());
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream()); DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
System.out.println("Assigning new thread for this client"); System.out.println("Assigning new thread for this client");
outputStream.writeUTF("{Server} Connection Successful\n"); outputStream.writeUTF("{Server} Connection Successful\n");
// create a new thread object // Create a server thread
Thread thread = new Thread(new ServerThread(socket, inputStream, outputStream)); executor.submit(new ServerThread(socket, inputStream, outputStream));
// Invoking the start() method } catch (Exception e) {
thread.start(); if (socket != null) {
socket.close();
} catch (Exception e) { }
if (socket != null) { e.printStackTrace();
socket.close();
} }
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