Skip to content

Commit

Permalink
Update Client.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedi6431 authored Jul 7, 2024
1 parent 3b1663c commit 72ec41f
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,31 @@ public class Client {
public static void Initialize(String address, int port) {
try {
// establish a connection with the server
System.out.println("\nClient started");
Socket socket = new Socket(address, port);
System.out.println("Client connected");


// get input from the terminal
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

// send output to the server socket
DataOutputStream output = new DataOutputStream(socket.getOutputStream());


// string to read input
String line = "";
boolean linux;


// IP of the server and the client
String serverIP = socket.getLocalAddress().getHostAddress();
String clientIP = Inet4Address.getLocalHost().getHostAddress();


// ask the system that use the server to write custom payloads
System.out.println("\nChoose the system that using the server");
System.out.println("1 Linux");
System.out.println("2 Windows\n");
System.out.print("--> ");
Scanner scanner = new Scanner(System.in);
int userSystem = scanner.nextInt();

if (userSystem == 1) {
linux = true;
output.writeUTF(String.valueOf(linux));
} else if (userSystem == 2) {
linux = false;
output.writeUTF(String.valueOf(linux));
} else {
System.out.println("Syntax error, select one of the options");
}

// loop until "exit" is written
while (!line.equalsIgnoreCase("exit")) {
// get user input
System.out.print(clientIP + " to " + serverIP + "$-");
line = reader.readLine();

// send the received input to the server
output.writeUTF(line);
}

// close the connection
output.close();
socket.close();
Expand All @@ -72,10 +49,12 @@ public static void Initialize(String address, int port) {
}

public static void main(String args[]) {

System.out.println("Made by Fedi6431");
System.out.println("Type server IPv4");
Scanner scanner = new Scanner(System.in);
String address = scanner.nextLine();

Initialize(address, 65000);
}
}

0 comments on commit 72ec41f

Please sign in to comment.