blob: 816d0976328d2045c981fb2205332c048a646d7a (
plain)
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
|
import java.util.*;
import java.io.*;
import java.net.*;
class ChatClient
{
public static void main(String[] args)
{
Socket s;
BufferedReader br, tr;
BufferedWriter bw;
InetAddress address = null;
int port = 0;
tr = new BufferedReader(new InputStreamReader(System.in));
try{
address = InetAddress.getByName(args[0]);
port = Integer.parseInt(args[1]);
}catch (UnknownHostException ex)
{
ex.printStackTrace();
}
try
{
System.out.printf("Connecting...\n");
s = new Socket(address, port);
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
System.out.printf("Client>");
while(true)
{
bw.write(tr.readLine());
bw.newLine();
bw.flush();
System.out.printf("%s: %s\n%s>", "Server", br.readLine(), "Client");
}
} catch (Exception e)
{
e.printStackTrace();
}
}
}
|