Socket长连接,字节发送

匿名 (未验证) 提交于 2019-12-02 23:03:14
    LogKit.error("IP连接");             Socket socket = new Socket("192.168.1.172", 5001);             OutputStream outputStream = socket.getOutputStream();             PrintStream dos = new PrintStream(outputStream);             byte[] bsa=new byte[1024];             bsa[0]=(byte) 0xFF;             bsa[1]=(byte) 0x00;             bsa[2]=(byte) 0x08;             bsa[3]=(byte) 0x63;             bsa[4]=(byte) 0x91;             bsa[5]=(byte) 0x89;             bsa[6]=(byte) 0x76;             bsa[8]=(byte) 0x18;             bsa[18]=(byte) 0xFB;             dos.write(bsa);             byte[] b = new byte[1024];             while(true) {                  InputStream inputStream = socket.getInputStream();                 inputStream.read(b);                 StringBuilder ipStr = new StringBuilder();                 for (byte bs : b) {                     if (bs < 0) {                         ipStr.append("." + (bs & 0xFF));                     } else if (bs == 0) {                         continue;                     } else {                         ipStr.append("." + (int) bs);                     }                                      }                 String ip1 = ipStr.toString();                 ip1 = ip1.substring(1);                 System.out.println(ip1);                              }                               }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!