-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestServer.java
67 lines (37 loc) · 1.12 KB
/
TestServer.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.*;
import java.net.*;
class TestServer
{
private static Socket socket;
public static void main(String args[])
{
try
{
//args[0]="8080";
ServerSocket serverSocket=new ServerSocket(Integer.parseInt(args[0]));
System.out.println("Listening to port :"+args[0]);
while(true)
{
socket=serverSocket.accept();
System.out.println("Connected to Client : "+ socket.getRemoteSocketAddress());
InputStream is=socket.getInputStream();
BufferedReader xx=new BufferedReader(new InputStreamReader(is),1);
System.out.println("Test");
String message=xx.readLine();
System.out.println("Test");
System.out.println("The Client "+socket.getRemoteSocketAddress().toString()+" says : "+ message);
BufferedReader xxx=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the message to send :");
String s=xx.readLine();
OutputStream os=socket.getOutputStream();
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os));
bw.write(s);
bw.flush();
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}