android下tcp之client测试
16lz
2021-01-23
new Thread(new Runnable() {@Overridepublic void run() {int count = 0;while (true) {try {Socket socket = new Socket("192.168.10.101", 60000);OutputStream os = socket.getOutputStream();String string = "tcp client count = "+count++;os.write(string.getBytes());os.flush();Thread.sleep(100);os.close();socket.close();} catch (UnknownHostException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} catch (InterruptedException e) {e.printStackTrace();} try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}}}}).start();
注意设置权限:
结果: 【Receive from 192.168.10.110 : 46736】:tcp client count = 0【Receive from 192.168.10.110 : 59447】:tcp client count = 1【Receive from 192.168.10.110 : 45333】:tcp client count = 2【Receive from 192.168.10.110 : 40047】:tcp client count = 3【Receive from 192.168.10.110 : 32905】:tcp client count = 4【Receive from 192.168.10.110 : 59586】:tcp client count = 5【Receive from 192.168.10.110 : 35389】:tcp client count = 6【Receive from 192.168.10.110 : 46435】:tcp client count = 7【Receive from 192.168.10.110 : 48257】:tcp client count = 8
更多相关文章
- Android 开机自启和后台自启权限
- android典型代码系列(十)------获取一个应用程序的权限信息(反射
- 【Android】Android 权限大全
- Android SDK1.0 Permission 大全访问权限许可
- 关于Android的app权限申请问题
- 在Android中通过Java修改文件权限
- Android:只需一句话解决读写权限授予后仍提示 Permission denied
- android判断是否禁用了录音权限