java.lang.Object
model.logic.server.MyServer
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
HostServer
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ClientHandlerprotected final intprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionMyServer(int port, ClientHandler clientHandler) Constructor for MyServer class. -
Method Summary
-
Field Details
-
port
protected final int port -
clientHandler
-
stop
protected volatile boolean stop
-
-
Constructor Details
-
MyServer
Constructor for MyServer class. Initializes the server with specified port number and client handler.- Parameters:
port- the port number to use for the serverclientHandler- the client handler to use for handling client connections
-
-
Method Details
-
start
public void start()Starts the server in a new thread.- Throws:
RuntimeException- if an error occurs while starting the server.
-
close
public void close()Closes the server and stops accepting new connections. Also, closes the client handler. -
runServer
Starts the server and listens for incoming client connections. Once a connection is established, the client handler is called to handle the client's input/output streams. The method runs in a loop until the server is stopped.- Throws:
Exception- if there is an error while creating or closing the server socket
-