Skip to content

Commit

Permalink
Update Server.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedi6431 authored Jun 26, 2024
1 parent 02c7589 commit f5a6f5d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ public class Server {
private ServerSocket server = null;
private DataInputStream input = null;

public Server(int port) {
public Server(String IP, int port) {
try {
// create a server socket
server = new ServerSocket(port);

InetAddress localIpAddress = InetAddress.getLocalHost();
System.out.println("Made by Fedi6431");
server = new ServerSocket();
System.out.println("Server started");
server.bind(new InetSocketAddress(localIpAddress, 5000));
System.out.println("Running on port 5000, IP: " + localIpAddress);



// establish a connection with the client
Expand Down Expand Up @@ -81,7 +86,12 @@ public Server(int port) {
}

public static void main(String args[]) {
InetAddress localIpAddress = InetAddress.getLocalHost();
server = new ServerSocket(5000, localIpAddress);
try {
InetAddress localIpAddress = InetAddress.getLocalHost();
String IP = localIpAddress.getHostAddress();
Server server = new Server(IP,5000);
} catch (UnknownHostException e) {
System.out.println("Error getting local host address: " + e.getMessage());
}
}
}

0 comments on commit f5a6f5d

Please sign in to comment.