sendInitialize();
isConnected = true;
+ } catch (SocketException e) {
+ return;
} catch (Exception e) {
e.printStackTrace();
throw e;
if (input != null)
input.close();
isConnected = false;
+ } catch (SocketException e) {
+ return;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (socket != null) {
try {
socket.close();
+ } catch (SocketException e) {
+ return;
} catch (IOException e) {
e.printStackTrace();
}
}
private void sendInitialize() throws IOException {
- String str = "telephony\n";
- output.write(str.getBytes(), 0, str.length());
- output.flush();
-
- byte[] abuf = { 0x04, 0x00, 0x40, 0x41 };
- output.write(abuf);
- output.flush();
-
- byte[] bbuf = { 0x16, 0x00, 0x00, 0x00 };
- output.write(bbuf);
- output.flush();
-
- output.write(str.getBytes(), 0, str.length());
- output.flush();
-
- byte[] cbuf = { 0x00, 0x00, 0x40, 0x47 };
- output.write(cbuf);
- output.flush();
-
- byte[] dbuf = { 0x00, 0x00, 0x40, 0x42 };
- output.write(dbuf);
- output.flush();
+ try {
+ String str = "telephony\n";
+ output.write(str.getBytes(), 0, str.length());
+ output.flush();
+
+ byte[] abuf = { 0x04, 0x00, 0x40, 0x41 };
+ output.write(abuf);
+ output.flush();
+
+ byte[] bbuf = { 0x16, 0x00, 0x00, 0x00 };
+ output.write(bbuf);
+ output.flush();
+
+ output.write(str.getBytes(), 0, str.length());
+ output.flush();
+
+ byte[] cbuf = { 0x00, 0x00, 0x40, 0x47 };
+ output.write(cbuf);
+ output.flush();
+
+ byte[] dbuf = { 0x00, 0x00, 0x40, 0x42 };
+ output.write(dbuf);
+ output.flush();
+ } catch (SocketException e) {
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
public void sendAskData() throws Exception {
if (!isConnected())
connect();
-
- String str = "telephony\n";
- output.write(str.getBytes(), 0, str.length());
- output.flush();
-
- byte[] buf = { 0x00, 0x00, 0x11, 0x5b };
- output.write(buf);
- output.flush();
+ try {
+ String str = "telephony\n";
+ output.write(str.getBytes(), 0, str.length());
+ output.flush();
+
+ byte[] buf = { 0x00, 0x00, 0x11, 0x5b };
+ output.write(buf);
+ output.flush();
+ } catch (SocketException e) {
+ disconnect();
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ disconnect();
+ throw e;
+ }
}
public void sendDispose() throws Exception {
if (!isConnected())
return;
- String str = "telephony\n";
- output.write(str.getBytes(), 0, str.length());
- output.flush();
-
- byte[] abuf = { 0x00, 0x00, 0x10, 0x01 };
- output.write(abuf);
- output.flush();
-
- byte[] bbuf = { 0x00, 0x00, 0x10, 0x02 };
- output.write(bbuf);
- output.flush();
+ try{
+ String str = "telephony\n";
+ output.write(str.getBytes(), 0, str.length());
+ output.flush();
+
+ byte[] abuf = { 0x00, 0x00, 0x10, 0x01 };
+ output.write(abuf);
+ output.flush();
+
+ byte[] bbuf = { 0x00, 0x00, 0x10, 0x02 };
+ output.write(bbuf);
+ output.flush();
+ } catch (SocketException e) {
+ disconnect();
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ disconnect();
+ throw e;
+ }
}
public boolean send(AbstractGA sendObj) throws Exception {
}
output.flush();
result = true;
+ } catch (SocketException e) {
+ disconnect();
+ return false;
} catch (Exception e) {
e.printStackTrace();
disconnect();
byte[] main = sensorMsg.getBytes();
if (main.length > 0) {
-// ByteUtil.printHex(main, "send body");
output.write(main, 0, main.length);
}
output.flush();
result = true;
+ } catch (SocketException e) {
+ disconnect();
+ return false;
} catch (Exception e) {
e.printStackTrace();
disconnect();
byte[] main = locationMsg.getBytes();
if (main.length > 0) {
-// ByteUtil.printHex(main, "send body");
output.write(main, 0, main.length);
}
output.flush();
result = true;
+ } catch (SocketException e) {
+ disconnect();
+ return false;
} catch (Exception e) {
e.printStackTrace();
disconnect();
}
output.flush();
result = true;
+ } catch (SocketException e) {
+ disconnect();
+ return false;
} catch (Exception e) {
e.printStackTrace();
disconnect();