Java多個客戶端同時連接服務端
import java
import java
public class ThreadServer extends Thread
{
private Socket client;
public ThreadServer(Socket c)
{
this
}
public void run()
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(client
PrintWriter out=new PrintWriter(client
//Mutil User but can
while (true)
{
String str=in
System
out
out
if (str
break;
}
client
}
catch (IOException ex)
{
}
finally
{
}
}
public static void main(String[] args)throws IOException
{
ServerSocket server=new ServerSocket(
while (true)
{
//transfer location change Single User or Multi User
ThreadServer mu=new ThreadServer(server
mu
}
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27248.html