android socket连接请教
如下代码所示,在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; mark=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
**********************************************************************************************************