当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Problems with exception errors when accessing a socket

问题描述:

Im playing with simple socket programming. The problem i have when i run this with the wrong ip address it just bombs out with a force close even though ive tried to catch all errors. Is there any other exception errors i can check for ?

 try {

String SocketIP = Global.privateSocketIP;

String SocketPort = Global.privateSocketPort;

int SocketPrt = Integer.parseInt(SocketPort);

SocketAddress adr = new InetSocketAddress(SocketIP,SocketPrt);

CommSocket.connect(adr, 4000);

CommDataOutput = new PrintWriter(new BufferedWriter(new OutputStreamWriter(CommSocket.getOutputStream())), true);

CommDataInput = new BufferedReader(new InputStreamReader(

CommSocket.getInputStream()));

return "0";

} catch (SocketTimeoutException e) {

//String Timeout = e.getMessage();

return "1";

} catch (UnknownHostException e) {

System.err.println("Don't know about host.");

return "2";

} catch (IOException e) {

String neil = e.getMessage();

neil = neil + "";

System.err.println("Couldn't get I/O for "

+ "the connection to host.");

return "3";

} catch (Exception exc)

{

String mes = exc.getMessage();

mes = mes + "";

return "3";

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: