-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAndroidThread.java
More file actions
63 lines (52 loc) · 1.33 KB
/
AndroidThread.java
File metadata and controls
63 lines (52 loc) · 1.33 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
package finalServer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class AndroidThread extends Thread {
Socket client;
BufferedReader br;
PrintWriter pw;
AndroidThread(Socket s){
this.client=s;
try {
br = new BufferedReader(new InputStreamReader(client.getInputStream(),"UTF-8"));
pw= new PrintWriter(client.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(info);
}
public void run(){
String info;
try {
while(true){
info=br.readLine();
analysis(info); //分析数据
}
} catch (IOException e) {
//与客户端连接失败
e.printStackTrace();
//break;
}
}
private void analysis(String info) {
String str[]=info.split(",");
if(str[0].equals("predict")){
System.out.println(info);
pw.println("OK");
pw.flush();
try {
PrintWriter cpw= new PrintWriter(Server.charge.getOutputStream());
cpw.println(info);
cpw.flush();
System.out.println("服务器发给收费端预约信息:"+info);
} catch (IOException e) {
//与收费端连接失败
e.printStackTrace();
}
}
}
}