-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatClient.java
More file actions
52 lines (35 loc) · 1.19 KB
/
Copy pathChatClient.java
File metadata and controls
52 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package client;
import java.net.Socket;
import java.net.InetSocketAddress;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class ChatClient {
private static final String serverip = "142.31.1.59";
private static final int serverport = 1112;
public ChatClient(){
Scanner scan = new Scanner(System.in);
String name = null;
while(true){
System.out.println("Enter name : ");
name = scan.nextLine();
if(!name.isEmpty()){
break;
}
}
scan.close();
Socket sock = new Socket();
try{
sock.connect(new InetSocketAddress(serverip, serverport));
chatlog.out("client joined");
new ChatWindow(name, sock).show();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(sock.getOutputStream(), StandardCharsets.UTF_8),true);
String request = "join:" + name + "\r\n" ;
writer.println(request);
}
catch (Exception e){
}
}
}