package com.demo;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

import javax.swing.JTextArea;

//这个类是用来解析数据的
public class SocketData2 extends Thread{
  private Socket socket;
  private InputStream in;
  private JTextArea textArea;
  
  public SocketData2(Socket clientSocket, JTextArea textArea) {
      try {
          // 得到socket连接
          socket = clientSocket;
          this.textArea=textArea;
          // 得到客户端发来的消息
          in= socket.getInputStream();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  public void run() {
      try {
          byte[] buffer = new byte[1024];
          int len = -1;
          while ((len = in.read(buffer)) != -1) {
              //输出获取到所有字节  16进制
        	//  buffer[len]=(byte)temp;  
        	  String string = new String(buffer,0,len);
        	  System.out.println("客户端监听:"+string);
        	  textArea.append(new String(buffer,0,len)+"\n");
				ServiceSoketServerListenerThread.send(string);
			  
          }
      }catch (IOException e){
    	  
         // e.printStackTrace();
      }
  }
  public static final String bytesToHexString(byte[] bArray) {
        StringBuffer sb = new StringBuffer(bArray.length);
        String sTemp;
        for (int i = 0; i < bArray.length; i++) {
         sTemp =Integer.toHexString(0xFF & bArray[i]);
         if (sTemp.length() < 2)
          sb.append(0);
         sb.append(sTemp.toUpperCase());
        }
        return sb.toString();
   }
}
最近下载更多
jxd2007kl  LV2 2023年11月29日
谢小饭_  LV8 2022年1月21日
9843637  LV9 2021年12月15日
tangjj7260  LV18 2021年12月10日
dfz12345  LV4 2021年12月8日
 LV2 2021年6月16日
miner22  LV9 2021年5月27日
chat511  LV3 2021年5月12日
15508061020  LV1 2020年9月3日
BruceQ  LV14 2020年7月15日
最近浏览更多
zeng1206  LV5 2023年12月28日
jxd2007kl  LV2 2023年11月29日
jidea  LV2 2023年11月29日
阿布屋脊  LV7 2023年8月15日
fuyouou  LV5 2023年6月29日
CL200228  LV4 2023年5月4日
17771013609  LV4 2023年4月12日
sslhss 2022年11月30日
暂无贡献等级
2543317781 2022年11月26日
暂无贡献等级
罗清晨  LV11 2022年9月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友