📄 ccreceivethread.java
字号:
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
/**
* 客户端接收信息线程
* @author ij
*
*/
public class CCReceiveThread extends Thread {
private Socket s;
public CCReceiveThread() {
super();
}
public CCReceiveThread(Socket s) {
super();
this.s = s;
}
public void run() {
ObjectInputStream ois = null;
ChatMessage cm = null;
try {
while (true) {
ois = new ObjectInputStream(s.getInputStream());
ois.read();
cm = (ChatMessage) ois.readObject();
//根据操作符 进行处理
if (cm.getCurrent().equals("nameerr")) {
CCSInterface.jtavision.setText("设置的昵称:" + cm.getCliname()
+ "与聊天室中成员昵称重复 \n 本程序即将关闭,请重新运行设置新的昵称");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.exit(1);
}
if (cm.getCurrent().equals("sendname")
|| cm.getCurrent().equals("isnetadds")) {
String str = cm.getContent();
String[] arraystr = str.split(",");
String[] arraystr1 = new String[(arraystr.length + 1)];
;
arraystr1[0] = "发送给聊天室";
for (int i = 0; i < arraystr.length; i++) {
arraystr1[i + 1] = arraystr[i];
}
CCSInterface.jlist.setListData(arraystr1);
continue;
}
if (cm.getCurrent().equals("ptop")) {
if (CCSInterface.cliname.endsWith(cm.getCliname())) {
CCSInterface.jtavision.append("我悄悄地对"
+ cm.getCliname() + "说:" + cm.getContent()
+ "\n");
continue;
} else {
CCSInterface.jtavision.append(cm.getCliname()
+ "悄悄对你说:" + cm.getContent() + "\n");
continue;
}
}
if (CCSInterface.cliname.endsWith(cm.getCliname())) {
CCSInterface.jtavision.append("我说:" + cm.getContent()
+ "\n");
} else {
CCSInterface.jtavision.append(cm.getCliname() + "说:"
+ cm.getContent() + "\n");
}
}
} catch (IOException e) {
CCSInterface.jtavision.setText("无法连接到客户端,请确认客户端后,重新运行本程序");
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -