java.net.connectexception连接超时
嗨,我正在为rmi使用此代码 RmiServer.javajava.net.connectexception连接超时,java,rmi,Java,Rmi,嗨,我正在为rmi使用此代码 RmiServer.java import java.rmi.*; import java.rmi.registry.*; import java.rmi.server.*; import java.net.*; public class RmiServer extends java.rmi.server.UnicastRemoteObject implements ReceiveMessageInterface { int th
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.net.*;
public class RmiServer extends java.rmi.server.UnicastRemoteObject
implements ReceiveMessageInterface
{
int thisPort;
String thisAddress;
Registry registry; // rmi registry for lookup the remote objects.
// This method is called from the remote client by the RMI.
// This is the implementation of the gReceiveMessageInterfaceh.
public void receiveMessage(String x) throws RemoteException
{
System.out.println(x);
}
public RmiServer() throws RemoteException
{
try{
// get the address of this host.
thisAddress= (InetAddress.getLocalHost()).toString();
}
catch(Exception e){
throw new RemoteException("can't get inet address.");
}
thisPort=3232; // this port(registryfs port)
System.out.println("this address="+thisAddress+",port="+thisPort);
try{
// create the registry and bind the name and object.
registry = LocateRegistry.createRegistry( thisPort );
registry.rebind("rmiServer", this);
}
catch(RemoteException e){
throw e;
}
}
static public void main(String args[])
{
try{
RmiServer s=new RmiServer();
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
RmiClient.java
import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;
public class RmiClient
{
static public void main(String args[])
{
ReceiveMessageInterface rmiServer;
Registry registry;
String serverAddress=args[0];
String serverPort=args[1];
String text=args[2];
System.out.println("sending "+text+" to "+serverAddress+":"+serverPort);
try{
// get the �gregistry�h
registry=LocateRegistry.getRegistry(
serverAddress,
(new Integer(serverPort)).intValue()
);
// look up the remote object
rmiServer=
(ReceiveMessageInterface)(registry.lookup("rmiServer"));
// call the remote method
rmiServer.receiveMessage(text);
}
catch(RemoteException e){
e.printStackTrace();
}
catch(NotBoundException e){
e.printStackTrace();
}
}
}
ReceiveMessageInterface.java
import java.rmi.*;
public interface ReceiveMessageInterface extends Remote
{
public void receiveMessage(String x) throws RemoteException;
}
这在正常情况下可以正常工作,但当电脑通过手机连接到互联网或从其他pc共享互联网时,它就无法工作
我得到这个错误
java.net.connectexception连接超时
当我尝试telnet时,它无法连接,但当我尝试运行此程序时,电脑
到我的电脑,它的工作
请告诉我如何解决此问题。听起来像是防火墙或代理服务器问题。不,我不认为是防火墙问题。supoose我已经在我的机器上安装了一个虚拟机,并尝试运行相同的程序。当我第一次尝试连接在该虚拟机内运行的服务器程序时,它工作正常,但他无法连接。它显示相同的错误。因此,它从同一台计算机/子网内连接,但不从其他计算机/子网连接?如果是这样的话,那就是防火墙问题。我已经尝试在windows pc中停止防火墙,但它仍然无法连接到该pc。我不能告诉你多少。你必须一步一步地解决网络问题,我不能在这里帮你。你知道其他人已经成功了,所以你也可以:看看其他帖子,例如,[.'Telnet无法连接'=>这是一个网络连接问题,而不是编程问题。