-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp_server.java
More file actions
132 lines (112 loc) · 2.9 KB
/
App_server.java
File metadata and controls
132 lines (112 loc) · 2.9 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.util.*;
import encode_decode_package.*;
import java.io.*;
class queue_creator extends App_server implements Runnable
{
encode_decode_package.encode_decode l_oConvert=new encode_decode_package.encode_decode();
Thread t1;
queue_creator()
{
t1=new Thread(this);
t1.start();
}
public void run()
{
while(true)
{
// sending phase
if(list.size()!=0)
{
int length=list.size();
for(int i=0;i<length;i++)
{
sending_format temp= new sending_format();
temp=(sending_format) list.getFirst();
boolean status= sms_client.send(temp.phone_no,temp.secured_text_msg);
System.out.println(temp.phone_no+" "+temp.secured_text_msg);
if(status==true)
{
//System.out.println("message sent at :"+temp.curr_date_time);
}
else
{
//System.out.println("sending failed");
}
list.removeFirst();
}
}
//receiving phase
else if(sms_client.existence_of_msgs()==true)
{
return_format array_of_objs[]=sms_client.receive();
int length = array_of_objs.length;
sms_client=null;
try
{
PrintWriter out=new PrintWriter(new FileWriter("received_data.txt",true));
for(int i=0;i<length;i++)
{
String text_contents="";
text_contents=array_of_objs[i].phone_no+", "+array_of_objs[i].curr_date_time+", "+array_of_objs[i].read_date_time;
String temp=l_oConvert.Encode_Decode(array_of_objs[i].decoded_msg);
text_contents=", "+temp+"\n";
out.println(text_contents);
}
out.close();
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
//sleeping phase
else
{
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{
//System.out.println(ex.toString());
}
}
}
}
}
public class App_server
{
static LinkedList list=new LinkedList();
static SMSClient sms_client=new SMSClient();
public static void main(String v[]) throws IOException
{
String port_id="";
encode_decode_package.encode_decode l_oConvert=new encode_decode_package.encode_decode();
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the port id to open:");
port_id=read.readLine();
boolean status= sms_client.config_port(port_id);
if(status==false)
{
System.out.println("Error in opening port");
System.exit(0);
}
BufferedReader reader=new BufferedReader(new FileReader("sending_data.txt"));
queue_creator que=new queue_creator();
String dat1;
while(true)
{
while( (dat1= reader.readLine()) !=null)
{
//System.out.println("enter the phone number");
//System.out.println("enter the text");
//String text_msg=read.readLine();
String send_data[]=dat1.split(",");
String secured_text=l_oConvert.Encode_Decode(send_data[1]);
sending_format obj=new sending_format(send_data[0],secured_text); // send_data[0]= phone num and send_data[1]= the text message
list.addLast(obj);
}
reader.close();
}
}
}