Untitled
unknown
plain_text
2 years ago
1.3 kB
4
Indexable
import java.io.*; import java.net.*; public class Client { public static void main(String[] args) { String serverAddress = "127.0.0.1"; // Replace with the server IP address int portNumber = 12345; // Use the same port number as on the server side try { Socket clientSocket = new Socket(serverAddress, portNumber); System.out.println("Connected to Administration."); // Create I/O streams for communication BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); // Communication loop BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in)); String inputLine; while (true) { System.out.print("Client: "); String clientMessage = consoleReader.readLine(); out.println(clientMessage); if ((inputLine = in.readLine()) != null) { System.out.println("Admin: " + inputLine); } } } catch (IOException e) { e.printStackTrace(); } } }
Editor is loading...