📄 mythread.java
字号:
package com.sterning;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Iterator;
public class MyThread implements Runnable {
Socket s;
static ArrayList al;
DataInputStream din;
DataOutputStream dout;
MyThread(Socket s, ArrayList al) {
this.s = s;
this.al = al;
}
public void run() {
String str;
int i = 1;
try {
din = new DataInputStream(s.getInputStream());
} catch (Exception e) {
}
while (i == 1) {
try {
str = din.readUTF(); // read the message
distribute(str);
} catch (IOException e) {
}
}
}
// send it to all clients
public void distribute(String str) throws IOException {
Iterator i = al.iterator();
Socket st;
while (i.hasNext()) {
st = (Socket) i.next();
dout = new DataOutputStream(st.getOutputStream());
dout.writeUTF(str);
dout.flush();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -