-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
33 lines (26 loc) · 812 Bytes
/
Server.java
File metadata and controls
33 lines (26 loc) · 812 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
32
33
import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Server s= new Server();
s.run();
}
public void run() throws Exception{
//Create server socket on port 444
ServerSocket srvsock = new ServerSocket(4444);
//Create plain socket to accept from server socket
Socket sock=srvsock.accept();
//Input stream from socket
InputStreamReader IR= new InputStreamReader(sock.getInputStream());
BufferedReader BR = new BufferedReader(IR);
String message= BR.readLine();
//Received from client
System.out.println(message);
//Will be sent to client
if(message!=null){
PrintStream ps = new PrintStream(sock.getOutputStream());
ps.println("Hello from the other end!");
}
}
}