-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMyServer.java
More file actions
25 lines (21 loc) · 794 Bytes
/
MyServer.java
File metadata and controls
25 lines (21 loc) · 794 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
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class MyServer {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
final int PORTNO = 9999;
ServerSocket server = new ServerSocket(PORTNO);
// Server is Ready and Listing on Port no 9999
System.out.println("Server Start and Waiting for the Client");
Socket socket = server.accept(); // Client Comes and Handshaking Done
System.out.println("Client Comes");
System.out.println("Enter the Message Send to Client...");
String message = new Scanner(System.in).nextLine();
// Write Bytes on Socket
socket.getOutputStream().write(message.getBytes());
System.out.println("Data Send...");
socket.close();
}
}