-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.java
More file actions
33 lines (29 loc) · 798 Bytes
/
server.java
File metadata and controls
33 lines (29 loc) · 798 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
package socketp1;
import java.net.*;
import java.util.Scanner;
import java.io.*;
public class server
{
public static void main(String[] args)throws Exception
{
ServerSocket ss=new ServerSocket(4999);
Socket s=ss.accept();
System.out.println("client connected");
DataInputStream in=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
String str=in.readUTF();
System.out.println("Client: "+str);
if (str.equalsIgnoreCase("bye"))
break;
System.out.print("-> : ");
String inp=bf.readLine();
out.writeUTF(inp);
}
System.out.println("Connection closed");
s.close();
ss.close();
}
}