-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocServer.java
More file actions
23 lines (20 loc) · 893 Bytes
/
Copy pathSocServer.java
File metadata and controls
23 lines (20 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package SocketProgramming;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class SocServer {
public static void main(String[] args) throws Exception{
System.out.println("SocketProgramming.Server Starting");
try (ServerSocket ss = new ServerSocket(9999)) {
System.out.println("Waiting for connection");
Socket s=ss.accept();//accept any connection request made to server and make a child socket to tha client
System.out.println("Connection established with client");
BufferedReader reader=new BufferedReader(new InputStreamReader(s.getInputStream()));
String st= reader.readLine();
System.out.println("Clients msg is "+st);
} catch (Exception e) {
System.out.println("Port's busy");
}
}
}