-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathServer.java
More file actions
25 lines (22 loc) · 760 Bytes
/
Server.java
File metadata and controls
25 lines (22 loc) · 760 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.*;
import java.net.*;
import java.util.Scanner;
public class Server
{
public static void main(String[] args) throws Exception
{
System.out.println("Server ready for communication");
ServerSocket serverSocket=new ServerSocket(4000);
Socket socket=serverSocket.accept();
InputStream iStream=socket.getInputStream();
Scanner sin=new Scanner(iStream);
String fname=sin.next();
OutputStream oStream=socket.getOutputStream();
PrintWriter pWriter=new PrintWriter(oStream,true);
File file=new File(fname);
Scanner fin=new Scanner(file);
while(fin.hasNext())
pWriter.println(fin.next());
System.out.println("Connection is successful and file contents are displayed in the client window");
}
}