-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathServer.java
More file actions
39 lines (24 loc) · 886 Bytes
/
Server.java
File metadata and controls
39 lines (24 loc) · 886 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
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class Server {
public static void main(String[] args) throws IOException {
final int PORTNO = 9001;
ServerSocket serverSocket = new ServerSocket(PORTNO);
System.out.println("Waiting for the Client....");
Socket socket = serverSocket.accept(); // this is for handshaking
System.out.println("Here comes the client...");
System.out.println("Enter the Message to Send..");
Scanner scanner = new Scanner(System.in);
String message = scanner.nextLine();
socket.getOutputStream().write(message.getBytes());
System.out.println("Data Send to the Client...");
socket.close();
scanner.close();
// OutputStream os = socket.getOutputStream();
// byte bArray []= message.getBytes();
// os.write(bArray);
}
}