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



更多相关文章

  1. Android必会小功能总结
  2. ListView多次调用getView方法
  3. android camera根据屏幕图像大小设置显示
  4. Android(安卓)实现微信登录
  5. android Paint 设置线宽setStrokeWidth()的单位
  6. android获取mac地址方法
  7. Android完全退出应用程序的方法
  8. Android设置StatusBar颜色
  9. android 设置progressbar的背景颜色

随机推荐

  1. 带你了解Android接口回调机制
  2. Android让页面默认弹出输入法的问题
  3. android 启动页和如何判断app是否第一次
  4. 《Android外部存储》
  5. android 系统签名
  6. Android(安卓)ComboBox
  7. Android 最简单的二维码和条形码扫描生成
  8. Android studio 安卓炫酷动画整合
  9. Android底部导航栏之RadioButton
  10. Context都没弄明白,还怎么做Android开发?