标签:system main integer int tac col data style hex
package com.ygkj.test; import java.io.*; import java.net.*; public class Test20171226 { private static final int PORT=9000; private static final String HOST="192.168.2.200"; public static void main(String[] args) { test1(); } public static void test1() { Socket socket = null; DataInputStream dis = null; InputStream istr = null; byte[] buffer = null; try { socket = new Socket(HOST,PORT); while(true) { istr = socket.getInputStream(); //dis = new DataInputStream(istr); buffer = new byte[istr.available()]; while(istr.read(buffer)>0) { //System.out.println("receive_msg:"+buffer); printHexString(buffer); System.out.println(""); } } }catch(Exception e) { e.printStackTrace(); } } public static void printHexString(byte[] b) { String str = ""; for(int i=0;i<b.length;i++) { String hex = Integer.toHexString(b[i]&0xFF); if(hex.length()==1) { hex = ‘0‘+hex; } str = str+hex.toUpperCase(); } char[] strChar = str.toCharArray(); for(char aa :strChar) { System.out.print(aa); } } }
标签:system main integer int tac col data style hex
原文地址:https://www.cnblogs.com/herd/p/11830909.html