- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
Latest commit
33 lines (26 loc) · 812 Bytes
/
Copy pathServer.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
importjava.io.*;
importjava.net.*;
publicclassServer {
publicstaticvoidmain(String[] args) throwsException {
// TODO Auto-generated method stub
Servers= newServer();
s.run();
}
publicvoidrun() throwsException{
//Create server socket on port 444
ServerSocketsrvsock = newServerSocket(4444);
//Create plain socket to accept from server socket
Socketsock=srvsock.accept();
//Input stream from socket
InputStreamReaderIR= newInputStreamReader(sock.getInputStream());
BufferedReaderBR = newBufferedReader(IR);
Stringmessage= BR.readLine();
//Received from client
System.out.println(message);
//Will be sent to client
if(message!=null){
PrintStreamps = newPrintStream(sock.getOutputStream());
ps.println("Hello from the other end!");
}
}
}