public
void
op() {
StringBuilder sb =
new
StringBuilder();
String ch;
String ch2;
try
{
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if
(conn !=
null
) {
conn.setConnectTimeout(
10000
);
conn.setUseCaches(
false
);
status.setText(String.valueOf(conn.getResponseCode()) +
"\n"
+ String.valueOf(HttpURLConnection.HTTP_OK));
status2.setText(String.valueOf(conn.getResponseCode()) +
"\n"
+ String.valueOf(HttpURLConnection.HTTP_OK));
if
(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader br =
new
BufferedReader(
new
InputStreamReader(conn.getInputStream()));
while
(
true
) {
String line = br.readLine();
if
(line ==
null
)
break
;
sb.append(line +
"\n"
);
}
br.close();
}
else
{
status.setText(
"http_not"
);
status2.setText(
"http_not"
);
}
conn.disconnect();
}
}
catch
(Exception e) {
status.setText(e.toString());
status2.setText(e.toString());
}
String jsonString = sb.toString();
try
{
int
data1 =
0
;
int
data2 =
0
;
JSONArray ja =
new
JSONArray(jsonString);
data1 = ja.getJSONObject(
0
).getInt(
"cb1_status"
);
data2 = ja.getJSONObject(
1
).getInt(
"cb1_status"
);
if
(data1 ==
1
) {
ch =
"가동중"
;
status.setText(ch);
return
;
}
else
if
(data1 ==
0
) {
ch =
"정지"
;
status.setText(ch);
return
;
}
if
(data2 ==
1
) {
ch2 =
"가동중"
;
status2.setText(ch2);
}
else
if
(data2 ==
0
) {
ch2 =
"정지"
;
status2.setText(ch2);
}
}
catch
(JSONException e) {
status.setText(e.toString());
status2.setText(e.toString());
}
}