Socket长连接,字节发送

    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);
                
            }
            
            
    }

猜你喜欢

转载自www.cnblogs.com/nancheng/p/10159801.html
今日推荐