android下tcp之client测试
16lz
2022-05-27
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必会小功能总结
- ListView多次调用getView方法
- android camera根据屏幕图像大小设置显示
- Android(安卓)实现微信登录
- android Paint 设置线宽setStrokeWidth()的单位
- android获取mac地址方法
- Android完全退出应用程序的方法
- Android设置StatusBar颜色
- android 设置progressbar的背景颜色