-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatTest.java
More file actions
24 lines (20 loc) · 830 Bytes
/
ChatTest.java
File metadata and controls
24 lines (20 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.ServerSocket;
public class ChatTest {
public static void main(String[] args) throws UnknownHostException, IOException {
// Scanner scanner = new Scanner(System.in);
String clientName = args[0];
System.out.println("Enter your name: ");
Socket socket = new Socket("localhost", 8080);
Client client = new Client(socket, clientName);
// These are blocking methods
// The client will not be able to send messages until it receives a message from
// the server
// Since they are sperate threads, the client can send messages and listen for
// messages at the same time
client.listenForMessage();
client.sendMessage();
}
}