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();
}
}
最近下载更多
qwertasdfgkwuejwjwjw LV1
2024年6月27日
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日
最近浏览更多
13133117021 LV5
2024年12月23日
124324343 LV1
2024年6月29日
qwertasdfgkwuejwjwjw LV1
2024年6月27日
taoshen95 LV16
2024年6月18日
周鸣郝 LV2
2024年5月26日
微信网友_7004855557083136 LV1
2024年5月22日
zeng1206 LV7
2023年12月28日
jxd2007kl LV2
2023年11月29日
jidea LV2
2023年11月29日
阿布屋脊 LV7
2023年8月15日

