首页 > 其他 > 详细

Socket长连接,字节发送

时间:2018-12-22 10:59:48      阅读:186      评论:0      收藏:0      [点我收藏+]
    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);
                
            }
            
            
    }

 

Socket长连接,字节发送

原文:https://www.cnblogs.com/nancheng/p/10159801.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!