如下代码所示,在andorid stuio中我创建了个SocketThread线程,然后试图在里面进行网络连接,ip,端口设置都正确 ,同事我在android Manifest文件中也添加了网络权限,但是我在调试的时候每次获取的socket对象都为空,请问一下这是什么原因,快被整崩溃了
------------------------------------------------------------------------------------------------
public void conn() { try {
Log.i(TAG, "连接中……");
//client = new Socket(Ip, Port);
Socket client = new Socket(Ip, Port);
client.setSoTimeout(timeout); // 设置阻塞时间
Log.i(TAG, "连接成功");
in = client.getInputStream();
out = client.getOutputStream();
out.write("haha,shouji fasong chenggong ".getBytes());
out.flush();
Log.i(TAG, "输入输出流获取成功");
} catch (UnknownHostException e) {
Log.i(TAG, "连接错误UnknownHostException 重新获取");
e.printStackTrace();
//conn();
} catch (IOException e) {
Log.i(TAG, "连接服务器io错误");
e.printStackTrace();
} catch (Exception e) {
Log.i(TAG, "连接服务器错误Exception" + e.getMessage());
e.printStackTrace();
}
}
-------------------------------------------------------------------------------------------------------------------------------------调试捕捉到的代码
**********************************************************************************************************
07-09 12:35:53.217 12041-12041/smarthome.hackha.wificonnection I/socket thread: 创建线程socket
07-09 12:35:53.218 12041-12041/smarthome.hackha.wificonnection I/socket thread: 连接中……
07-09 12:35:53.236 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: [getaddrinfo]: mtk hostname=192.168.1.6; servname=(null); cache_mode=(null), netid=0; =0
07-09 12:35:53.236 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: getaddrinfo( app_uid:10128
07-09 12:35:53.236 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: getaddrinfo() uid prop:
07-09 12:35:53.237 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: getaddrinfo() getuid():10128
07-09 12:35:53.237 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: [getaddrinfo]: mtk ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
07-09 12:35:53.243 12041-12041/smarthome.hackha.wificonnection I/System.out: [CDS]connect[/192.168.1.6:8080] tm:90
07-09 12:35:53.252 12041-12041/smarthome.hackha.wificonnection I/socket thread: 连接服务器错误Exceptionnull
**********************************************************************************************************
------------------------------------------------------------------------------------------------
public void conn() { try {
Log.i(TAG, "连接中……");
//client = new Socket(Ip, Port);
Socket client = new Socket(Ip, Port);
client.setSoTimeout(timeout); // 设置阻塞时间
Log.i(TAG, "连接成功");
in = client.getInputStream();
out = client.getOutputStream();
out.write("haha,shouji fasong chenggong ".getBytes());
out.flush();
Log.i(TAG, "输入输出流获取成功");
} catch (UnknownHostException e) {
Log.i(TAG, "连接错误UnknownHostException 重新获取");
e.printStackTrace();
//conn();
} catch (IOException e) {
Log.i(TAG, "连接服务器io错误");
e.printStackTrace();
} catch (Exception e) {
Log.i(TAG, "连接服务器错误Exception" + e.getMessage());
e.printStackTrace();
}
}
-------------------------------------------------------------------------------------------------------------------------------------调试捕捉到的代码
**********************************************************************************************************
07-09 12:35:53.217 12041-12041/smarthome.hackha.wificonnection I/socket thread: 创建线程socket
07-09 12:35:53.218 12041-12041/smarthome.hackha.wificonnection I/socket thread: 连接中……
07-09 12:35:53.236 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: [getaddrinfo]: mtk hostname=192.168.1.6; servname=(null); cache_mode=(null), netid=0; =0
07-09 12:35:53.236 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: getaddrinfo( app_uid:10128
07-09 12:35:53.236 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: getaddrinfo() uid prop:
07-09 12:35:53.237 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: getaddrinfo() getuid():10128
07-09 12:35:53.237 12041-12041/smarthome.hackha.wificonnection D/libc-netbsd: [getaddrinfo]: mtk ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
07-09 12:35:53.243 12041-12041/smarthome.hackha.wificonnection I/System.out: [CDS]connect[/192.168.1.6:8080] tm:90
07-09 12:35:53.252 12041-12041/smarthome.hackha.wificonnection I/socket thread: 连接服务器错误Exceptionnull
**********************************************************************************************************
解决方案 »
- 彩信不能接收音频文件
- 真集图片内存泄露,怎么解决?
- 求教,bitmap大小不对,opengl无法绘制,需要转成2次幂,如何转?
- Android2.2 怎么往SIM卡里插入联系人
- 求日历编写思路?
- tabhost出现的问题
- 请问, android下的应用程序中, 想在以下语句中加时间输出信息, 如何加呢? (不知函数名称)
- 关于Android画图程序中的Canvas类使用的疑问
- 咨询一个关于DrawerLayout的问题
- 百度定位API的定位数据获得
- 使用md5将账号和密码存储在preferences后,那该如何实现记住密码功能呢
- android开发:怎么让app安装的时候默认勾选后台运行、信任该应用等选择呢
Log.i(TAG, "连接服务器错误Exception" + e.getClass().getName());
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
居然就没事了,我也是醉了哦
卸载,再次安装又没问题了,