-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.java
More file actions
33 lines (32 loc) · 1.08 KB
/
server.java
File metadata and controls
33 lines (32 loc) · 1.08 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
import java.io.*;
import java.net.*;
// read and write both server and client side.
public class server {
public static void main(String[] args) {
try {
ServerSocket ss=new ServerSocket(5000);
System.out.println("waiting for client...");
Socket s=ss.accept();
System.out.println("connected successfully!!");
DataInputStream din=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String in="";
String out="";
while(!in.equals("stop"))
{
in=din.readUTF();
System.out.println("Client: "+in);
System.out.print("Server: ");
out=br.readLine();
dout.writeUTF(out);
dout.flush();
}
din.close();
s.close();
ss.close();
} catch (Exception e) {
System.out.println(e);
}
}
}