blob: 325961176985449fd2bf99a8367c6dc4ac2f4046 (
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
|
import java.io.*;
import java.util.*;
import java.net.*;
class ChatServer
{
public static void main(String[] args)
{
ServerSocket ss;
Socket s;
BufferedReader br, tr;
BufferedWriter bw;
tr = new BufferedReader(new InputStreamReader(System.in));
try
{
ss = new ServerSocket(2452);
s = ss.accept();
System.out.printf("Client connected...\n");
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
//String[] address = new String[2];
//address[0] = InetAddress.toString(s.getAddress());
//address[1] = InetAddress.toString(s.getLocalAddress());
while(true)
{
System.out.printf("%s: %s\n%s>", "Client", br.readLine(), "Server");
bw.write(tr.readLine());
bw.newLine();
bw.flush();
}
}catch (Exception e)
{
e.printStackTrace();
}
}
}
|