java - RMI Chatprogram push configuration on external network not working -
we're trying make simple chat program using rmi push configuration. program works on internal network, when trying run program server on external network, error:
java.rmi.connectexception: connection refused host: 192.168.1.13; caused by: java.net.connectexception: connection timed out: connect
the error occurs when client calls method 'broadcast(string s)' on interface 'ichatserver' method located on server , calls other clients subscribed listener on server.
our client can connect server. can bindings registry , call methods server.
but when server tries call method client, error.
on server, port 1099 forwarded, , port 1099 allowed in firewall.
is there way make possible (using rmi)? or ports on client side need forwarded?
server:
try { string theip = serverhostexternalip; system.setproperty("java.rmi.server.hostname", theip); //implemented no random ports used rmisocketfactory.setsocketfactory(new fixedportrmisocketfactory()); registry = locateregistry.createregistry(port_number); publisher = new remotepublisher(); publisher.registerproperty(binding_name); unicastremoteobject.unexportobject(server, true); unicastremoteobject.exportobject(server, port_number); unicastremoteobject.unexportobject(publisher, true); unicastremoteobject.exportobject(publisher, port_number); registry.rebind(binding_name, server); registry.rebind(publish_name, publisher); } catch (remoteexception ex) { system.err.println("[server] cannot bind student administration"); system.err.println("[server] remoteexception: " + ex.getmessage()); }
ichatserver:
public synchronized void tryconnect(string s, ichatclient client) throws remoteexception { system.out.println("[server] user connected: " + s); } public synchronized void broadcast(string s) throws remoteexception { // when line called, no errors occur, , string printed correctly. system.out.println("[message] " + s); //on line, server tries reach clients (all listeners) //this line of code generate error. publisher.inform(binding_name, null, s); }
client:
try { registry = locateregistry.getregistry(ipaddress, port_number); mycs = (ichatserver) registry.lookup(binding_name); //this method located on server , called without errors. mycs.tryconnect(userid, this); publisher = (iremotepublisherforlistener) registry.lookup(publish_name); publisher.subscriberemotelistener(this, binding_name); } catch (remoteexception ex) { system.err.println("[client] cannot lookup or subscribe publisher"); system.err.println("[client] remoteexception: " + ex.getmessage()); registry = null; } catch (notboundexception e) { system.err.println("[client] cannot lookup or subscribe publisher"); system.err.println("[client] notboundexception: " + e.getmessage()); registry = null; }
for rmi manner, dont think of sides client-server rather remote service
, caller
.
so caller
needs able connect via tcp remote service
in order perform remote method invocation (rmi). in case, port forwarding must set propely on both sides. can troublesome (eg client can behind nat not managed - in case) better threat rmi more rest service - 1 side calling remote service
besides forwarding 1099
whitch rmi registry port, have forward ports used exported objects. rmi registry holds informations how connect actual exported object handler.
Comments
Post a Comment