一个简单的网络通信程序,在98下可以通信,在xp下不行,请大虾看看为什么?附程序,很简单!
xddjd 2003-06-09 09:58:58 Socket端的程序:
import java.io.*;
import java.net.*;
public class Server
{
public static final int PORT = 8080;
public static void main(String[] args) throws IOException
{
ServerSocket s = new ServerSocket(PORT);
System.out.println("ServerSocket:" + s);
try
{
Socket socket1 = s.accept();
try
{
System.out.println("Connection to client accepted:" + socket1);
System.out.println("remote getInetAddress()="+ socket1.getInetAddress());
System.out.println("local getLocalAddress()=" + socket1.getLocalAddress());
System.out.println("local getLocalPport()=" + socket1.getLocalPort());
System.out.println("remote getPort()=" + socket1.getPort());
}
finally
{
System.out.println("closing socket");
socket1.close();
}
}
finally
{
s.close();
}
}
}
Client端的程序
import java.io.*;
import java.net.*;
public class Client
{
public static void main(String[] args) throws IOException
{
Socket socket1 = new Socket(args[0],Integer.parseInt(args[1]));
try
{
System.out.println("Connection to server accepted:" + socket1);
System.out.println("remote getInetAddress()="+ socket1.getInetAddress());
System.out.println("local getLocalAddress()=" + socket1.getLocalAddress());
System.out.println("local getLocalPport()=" + socket1.getLocalPort());
System.out.println("remote getPort()=" + socket1.getPort());
}
finally
{
System.out.println("closing socket");
socket1.close();
}
}
}
只是建立一个简单的连接,两个程序在同一台计算机运行,但是98下运行正常,即建立连接,屏幕输出,但是在winxp下不行?为什么?请指点!