-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClientAndroid.java
More file actions
75 lines (58 loc) · 1.62 KB
/
ClientAndroid.java
File metadata and controls
75 lines (58 loc) · 1.62 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
package com.example.androidclient;
import java.io.*;
import java.io.PrintWriter;
import java.net.*;
import java.net.UnknownHostException;
public class ClientAndroid extends Thread {
final String IP="192.168.1.107";//"10.20.179.1";//"10.40.140.14";//"192.168.1.107";
final int PORT=12000;
static public PrintWriter pw;
private BufferedReader br;
public ClientAndroid() {
}
@Override
public void run() {
try {
Socket socket=new Socket(IP,PORT);
pw= new PrintWriter(socket.getOutputStream());
br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
pw.println("predict,predict");
pw.flush();
MainActivity.connect=true;
} catch (UnknownHostException e) {
//MainActivity.notice.setText("连接服务器失败");
e.printStackTrace();
} catch (IOException e) {
// MainActivity.notice.setText("连接服务器失败");
e.printStackTrace();
}
String message;
try {
while(true){
message=br.readLine();
//System.out.println("仓库从服务器收到的信息:"+message);
analysis(message); //分析数据
}
} catch (IOException e) {
//连接失败
e.printStackTrace();
}
}
private void analysis(String message) {
new Thread(){
@Override
public void run() {
// MainActivity.notice.setText("sad");
}
}.start();
if(message.equals("OK")){
}
else{
//MainActivity.notice.setText("此部门现在没有医生,预约失败");
}
}
static public void sendInfo(String info){
pw.println("predict,"+info);
pw.flush();
}
}