Client
unknown
java
5 years ago
1.0 kB
6
Indexable
package chat.client;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;
public class Client {
private Socket socket;
private DataInputStream input;
private DataOutputStream output;
public Client() throws Exception {
socket = new Socket(InetAddress.getLocalHost(), 4444);
System.out.println("Client started!");
input = new DataInputStream(socket.getInputStream());
output = new DataOutputStream(socket.getOutputStream());
Scanner scanner = new Scanner(System.in);
while (true) {
String message = scanner.nextLine();
output.writeUTF(message);
message = input.readUTF();
System.out.println(message);
}
}
public static void main(String[] args) {
try {
new Client();
} catch (Exception e) {
e.printStackTrace();
}
}
}Editor is loading...