InetAddress addr= InetAddress.getByName(null);
这个有问题!!!!!
import java.net.*;
import java.io.*;class TcpClientThread extends Thread{
private Socket s; 
private static int count=0;
private int id=count++;
private int identifier;
private BufferedReader in;
private PrintWriter out;public TcpClientThread(InetAddress addr)
{
System.out.println("Making Client"+id);
try{
s=new Socket(addr,80);
}catch(IOException e){
System.out.println("cant  make client Socket");      
}
try{ 
in=new BufferedReader(new InputStreamReader(s.getInputStream()));
out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(
s.getOutputStream())),true);
start();}catch(IOException e){
System.out.println("cant't make in and out Stream");
try{
s.close();
}catch(IOException e2){
System.out.println("can't correctly close client socket");
}
}}
public void run(){
try{
for(int i=0;i<2;i++){
String str=new String("client #"+id+" Message #"+i);
out.println(str);
System.out.println(str);
str=in.readLine();
System.out.println(str);
}
out.println("end");
}catch(IOException e){
}finally{
try{ 
s.close();
System.out.println("Client socket is Closing");
}catch(IOException e){}}
}
}
public class TcpClient {public static void main(String args[])
throws IOException ,InterruptedException
{
InetAddress addr= InetAddress.getByName("127.0.0.1");
System.out.println("Remote Server addr is:"+addr); new TcpClientThread(addr);
}
}你把端口打开,我在80端口打开了apache服务。运行结果如下:
Remote Server addr is:127.0.0.1/127.0.0.1
Making Client0
client #0 Message #0