是这样的private void connection(){
try {
mSend =new Socket("192.168.33.66", 8888);
toastText("链接成功");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
toastText("连接失败"+e.getMessage());
Log.e("ssss",e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
toastText("连接失败"+e.getMessage());
Log.e("assss",e.getMessage());
}
}
打印出来的是:ailed to connect to /192.168.33.66 (port 8888): connect failed: ENETUNREACH (Network is unreachable)
try {
mSend =new Socket("192.168.33.66", 8888);
toastText("链接成功");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
toastText("连接失败"+e.getMessage());
Log.e("ssss",e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
toastText("连接失败"+e.getMessage());
Log.e("assss",e.getMessage());
}
}
打印出来的是:ailed to connect to /192.168.33.66 (port 8888): connect failed: ENETUNREACH (Network is unreachable)
ip地址我是看的电脑上当前的ip,端口我也换过的,应该不是端口的问题吧
是IP的问题,android默认PC的ip 是:10.0.2.2,
应该不是ip的问题,如果服务器不是当前pc,就只能根据ip找到机子
String url = "http://192.168.0.XXX:8080/imageservice/NewServlet";
try{
URL path = new URL(url);
HttpURLConnection con = (HttpURLConnection) path.openConnection();
// 判断是否连接真确
if (con.getResponseCode() == 200) { InputStream input = con.getInputStream();
return xmlParse(input);
}else{
System.out.println("yyyyyyyyyyyyyyyyy");
}
}catch(Exception e){
e.printStackTrace();