package com.demo;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import javax.swing.JTextArea;
//这个类是用来监听数据的
public class SocketData extends Thread{
private Socket socket;
private DataOutputStream dos;
private DataInputStream dis;
private JTextArea textField;
public SocketData(Socket clientSocket,JTextArea textField) {
this.textField=textField;
try {
// 得到socket连接
socket = clientSocket;
dis = new DataInputStream(socket.getInputStream());
// 得到客户端发来的消息
// in= socket.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
}
public void run() {
try {
while (true) {
String str = dis.readUTF();
System.out.println("------------来自本地服务器:" + str);
textField.append(str+"\n");
}
}catch (IOException e){
//e.printStackTrace();
}finally {
try {
if (dis != null)
dis.close();
if (dos != null)
dos.close();
if (socket != null) {
socket.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
最近下载更多
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日

