import java.net.Socket;
 import java.net.SocketException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 public class TCPClient {

public static void main(String[] args) throws IOException{

String server = "202.105.21.214";      // 服务器IP
   // 发送的数据
   byte data[] ={0x3F,0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0X00,0x00,0X00,0X00,0x05,0x24,0x78}; 
   byte[] recData=new byte[100];//接收数据缓冲
   int servPort = 16445;//端口
   Socket socket = new Socket(server, servPort);
   System.out.println("Connected to server...sending command string");
   InputStream in = socket.getInputStream();
   OutputStream out = socket.getOutputStream();
   out.write(data);  // 发送


   // 接收数据
   int totalBytesRcvd = 0;  // Total bytes received so far
  
   totalBytesRcvd=in.read(recData);//接收
   String hexString="";


    for(int i=0;i<totalBytesRcvd;i++)
     hexString+= Integer.toHexString(0xff&recData[i])+",";//转成十六进制显示
    System.out.println("Received: " + hexString);
               socket.close();  // Close the socket and its streams
}


 }