作者
附
import
import java
import java
import java
public class talkServer
{ public static void main(String[] args)
{ try
{ file://建立服務器
ServerSocket server = new ServerSocket(
int i=
for(;;)
{ Socket incoming = server
new ServerThread(incoming
i++;
}
}catch (IOException ex){
ex
}
}
}
class ServerThread extends Thread implements ActionListener
{
private int threadNum;
private Socket socket;
talkServerFrm t;
BufferedReader in;
PrintWriter out;
private boolean talking=true;
public ServerThread(Socket s
{ threadNum = c;
socket = s;
}
public void actionPerformed(ActionEvent e)
{ Object source = e
try{
if(source==t
{ out
t
}else
if(source==t
{ out
out
in
talking = false;
}
}catch(IOException ex){
}
}
public void run()
{ try{
t=new talkServerFrm(new Integer(threadNum)
t
t
in = new BufferedReader(new
InputStreamReader(socket
out = new PrintWriter(socket
}catch(Exception e){
}
new Thread()
{ public void run()
{ try{
while(true)
{ checkInput();
sleep(
}
}catch (InterruptedException ex){
}catch(IOException ex){
}
}
}
while(talking)
{ }
t
}
private void checkInput() throws IOException
{ String line;
if((line=in
t
file://用來將line的內容輸出到用戶界面
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25829.html