();
+
+ public static void main(String args[]) {
+
+ try {
+ serverSocket = new ServerSocket(port);
+ System.out.println("Server started at localhost:"+port);
+ } catch (IOException e) {
+ System.out.println(e);
+ }
+
+ /*
+ * Create a new client socket when a client is connecting
+ */
+ while (true) {
+ try {
+ clientSocket = serverSocket.accept();
+ ClientThread thread = new ClientThread(clientSocket, threads);
+ thread.start();
+ threads.add(thread);
+ } catch (IOException e) {
+ System.out.println(e);
+ }
+ }
}
}
diff --git a/src/server/ServerThread.java b/src/server/ServerThread.java
deleted file mode 100644
index 8311c9c..0000000
--- a/src/server/ServerThread.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package server;
-
-
-import java.net.*;
-import java.io.*;
-
-/**
- * ServerThread is the communication between client and server.
- * @author lenaic
- *
- */
-public class ServerThread extends Thread {
- private Socket socket = null;
- private Server server = null;
- private int id = -1;
- private DataInputStream streamIn = null;
-
- /**
- * Constructor of the class.
- * @param server : server.
- * @param socket : socket.
- */
- public ServerThread(Server server, Socket socket) {
- this.server = server;
- this.socket = socket;
- this.id = socket.getPort();
- }
-
- /**
- * Inform that a new user is connected.
- */
- public void run() {
- System.out.println("Client " + id + " connecté.");
- while (true)
- {
- try {
- System.out.println(streamIn.readUTF());
- }
- catch(IOException e) { }
- }
- }
-
- /**
- * Open the discussion channel.
- * @throws IOException
- */
- public void open() throws IOException {
- streamIn = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
- }
-
- /**
- * Close the discussion channel.
- * @throws IOException
- */
- public void close() throws IOException {
- if (socket != null)
- socket.close();
- if (streamIn != null)
- streamIn.close();
- }
-
-}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy