-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer2.java
More file actions
37 lines (32 loc) · 781 Bytes
/
Server2.java
File metadata and controls
37 lines (32 loc) · 781 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
25
26
27
28
29
30
31
32
33
34
35
36
import java.net.*;
import java.io.*;
class Server2
{
public static void main(String arg[])throws Exception
{
//create a server socket with some port no
ServerSocket ss=new ServerSocket(8888);
//connect it to cleint socket
Socket s=ss.accept();
System.out.println("connection established");
//to send data to the cleint
PrintStream ps=new PrintStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
//to read data comming from the cleient
BufferedReader kb=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
String str, str1;
while((str=br.readLine())!=null)
{
System.out.println(str);
str1=kb.readLine();
ps.println(str1);
}
ps.close();
br.close();
kb.close();
ss.close();
s.close();
System.exit(0);
}}}