Skip to content

Commit

Permalink
IP Address is now accepted as input in MercurysServer.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePurpleJedi committed Feb 22, 2022
1 parent 28977b4 commit 2365d7c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 1 addition & 3 deletions .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/com/mercurys/MercurysServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import com.mercurys.handlers.ServerSocketHandler;

import java.io.IOException;
import java.util.Scanner;

public class MercurysServer {

private ServerSocketHandler serverSocketHandler;

private MercurysServer(final int port) {
try {
serverSocketHandler = new ServerSocketHandler(port);
serverSocketHandler = new ServerSocketHandler(getIPAddress(), port);
} catch (final IOException e) {
System.out.println("Exception occurred!");
e.printStackTrace();
Expand All @@ -23,6 +24,11 @@ public static void main(final String[] args) {
System.out.println("Thank you for using Project Mercurys!");
}

private String getIPAddress() {
System.out.println("Enter your device's LAN IP address: ");
return new Scanner(System.in).nextLine();
}

private void startTalking() {
try {
serverSocketHandler.talkToClient();
Expand Down
7 changes: 3 additions & 4 deletions src/com/mercurys/handlers/ServerSocketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ public class ServerSocketHandler {
private MediaReaderThread incomingReaderThread;
private MessageHandler messageHandler;

public ServerSocketHandler(int serverPort) throws IOException {
public ServerSocketHandler(String hostIPAddress, int serverPort) throws IOException {
serverSocket = new ServerSocket();
initialiseServerSocket(serverPort);
initialiseServerSocket(hostIPAddress, serverPort);
acceptClientRequest();
initialiseIO();
}

private void initialiseServerSocket(int serverPort) throws IOException {
String hostAddress = "192.168.0.151"; //replace with one's own LAN IP address
private void initialiseServerSocket(String hostAddress, int serverPort) throws IOException {
serverSocket.bind(new InetSocketAddress(hostAddress, serverPort));
System.out.println("""
Server initiated.
Expand Down

0 comments on commit 2365d7c

Please sign in to comment.