-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.java
72 lines (60 loc) · 1.96 KB
/
Server.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.net.*;
import java.util.ArrayList;
import java.io.*;
class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket Server = new ServerSocket(8080);
System.out.println("Waiting for client to connect...");
Socket connection = Server.accept();
System.out.println("Connected ");
DataInputStream input=new DataInputStream(connection.getInputStream());
DataOutputStream output=new DataOutputStream(connection.getOutputStream());
String str=input.readUTF();
ArrayList<Details> a= new ArrayList<Details>();
try {
FileInputStream fin = new FileInputStream("D:\\Details.ser");
ObjectInputStream in = new ObjectInputStream(fin);
Details d;
while (true) {
d = (Details) in.readObject();
a.add(d);
}
}
catch (EOFException eof) {
System.out.println(" .... End of File ... ");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
StringBuilder det=new StringBuilder();
if(str.equals("byname")){
for(Details de:a)
{
det.append(de.name);
det.append("-");
det.append(de.cpi);
det.append(" ");
}
}
else{
for(Details de:a)
{
det.append(de.rno);
det.append("-");
det.append(de.cpi);
det.append(" ");
}
}
System.out.println(det);
output.writeUTF("Details:- " +det);
output.flush();
input.close();
connection.close();
Server.close();
}
}