Android studio4.0.1中客户端tcp socket连接报错s.connect()报错。所有可能引起报错的因素均已经排除。
```java
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
//s=new Socket("192.168.1.105",8888);
s=new Socket();
SocketAddress socketAddr = new InetSocketAddress("192.168.1.105", 8888);
s.connect(socketAddr);
dout=new DataOutputStream(s.getOutputStream());
din=new DataInputStream(s.getInputStream());
dout.writeUTF("reg");
String msg=din.readUTF();
tv1.setText(msg);
}catch(Exception e){
e.printStackTrace();
}
}
});
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
当执行s.connect()时抛出异常android.os.NetworkOnMainThreadException
```