-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoteArchiver.java
95 lines (81 loc) · 2.83 KB
/
NoteArchiver.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package notearchiveserver;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author maukhan.bscs13seecs
*/
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import static java.io.FileDescriptor.out;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import static java.lang.System.in;
import static java.lang.System.out;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JOptionPane;
import notearchiveserver.Notes;
public class NoteArchiver {
@SuppressWarnings("null")
public static void serve() throws IOException
{
ServerSocket listener = null;
try{
System.out.println("hello");
listener = new ServerSocket(1115);
while(true){
System.out.println("hello1");
Socket socket = listener.accept();
Notes n = null;
try{
FileOutputStream fileOut =
new FileOutputStream("Notes.ser");
FileInputStream fileIn = new FileInputStream("Notes.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
n = (Notes) in.readObject();
in.close();
fileIn.close();
}catch(IOException i){
i.printStackTrace();
return;
}catch(ClassNotFoundException c)
{
System.out.println("Employee class not found");
c.printStackTrace();
return;
}
System.out.println("Deserialized Employee...");
System.out.println("userName: " + n.username);
System.out.println("notes: " + n.notes);
/* String clientMsg="";
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println("Welcome to the Server");
clientMsg = input.readLine()+"|=>|";
System.out.println("GoodBye Client");
clientMsg += input.readLine();
System.out.println("client says:"+clientMsg);
*/
// finally{
socket.close();
//}
}
}
catch(Exception ex){
System.out.println("error maing socket in server");
}
finally{
listener.close();
}
}
}