Archived

This forum has been archived. Please start a new discussion on GitHub.

ConnectionRefusedException when calling client function from server side

Hello everybody!

I'm getting a little frustrated about this exception I get.

I'm having a java server whose code looks like this:
try {
	InitializationData initData = new InitializationData();
	initData.properties = Util.createProperties();
	initData.properties.setProperty("ServerAdapter.Endpoints", "default -p " + portNo + " -h " + serverAddress);
	initData.properties.setProperty("Ice.Warn.Connections", "1");
	initData.properties.setProperty("Ice.IPv6", "0");

	communicator = Ice.Util.initialize(initData);
	serverI = new RemoteCamServerI(controller);

	Ice.ObjectAdapter providerAdapter = communicator.createObjectAdapter("ServerAdapter");

	serverI.init(serverAddress);

	providerAdapter.add(serverI, communicator.stringToIdentity("Server"));
	providerAdapter.activate();

	logger.info("RemoteCamService() - running");

	running = true;
	fireChanged();

	communicator.waitForShutdown();
} catch (Ice.LocalException e) {
	//...
} catch (Exception e) {
	//...
}

On the other side I have the client with following implementation for a Windows Store App:
try
{
	string PortAddressAsString = IceUtil::wstringToString(PortAddress.ToString()->Data());
	string proxy = "Server:default -p " + PortAddressAsString + " -h " + ServerAddress;

	Ice::InitializationData id;
	id.properties = Ice::createProperties();
	id.properties->setProperty("Server.Proxy", proxy);
	id.properties->setProperty("ClientAdapter.Endpoints", "default");
	id.properties->setProperty("Ice.ACM.Client", "0");
	id.properties->setProperty("Ice.IPv6", "0");

	_communicator = Ice::initialize(id);

	ServerPrx = CsRemoteCamServerPrx::checkedCast(_communicator->propertyToProxy("Server.Proxy"));

	Ice::ObjectAdapterPtr adapter = _communicator->createObjectAdapter("ClientAdapter");

	RemoteClientAdapter* Client = new RemoteClientAdapter();
			
	Ice::Identity ident = _communicator->stringToIdentity("Client");
	adapter->add(Client, ident);
	adapter->activate();

	ClientPrx = CsRemoteCamClientPrx::uncheckedCast(adapter->createProxy(_communicator->stringToIdentity("Client")));

	ServerPrx->ice_getConnection()->setAdapter(adapter);

	ServerPrx->login(ClientPrx);
} catch (const Ice::Exception& ex)
{
	//...
}

When calling 'ServerPrx->login(ClientPrx)' everything is fine until I reach a function call back to the client. Then I get somethig like that:
-! 18.11.13 11:07:51:015 warning: Ice.ThreadPool.Server-0: dispatch exception:
   identity: Server
   facet: 
   operation: login
   remote host: 10.0.1.115 remote port: 50951
   Ice.ConnectionRefusedException
       error = 0
   	at IceInternal.ConnectRequestHandler.getConnection(ConnectRequestHandler.java:244)
   	at IceInternal.ConnectRequestHandler.sendRequest(ConnectRequestHandler.java:141)
   	at IceInternal.Outgoing.invoke(Outgoing.java:77)
...
Caused by: java.net.ConnectException: Connection refused: no further information
   	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
   	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)

The weird thing is: I have the same code running for both a java and an android client so I blame th WinRT environment for my problems.

Any suggestions what I am missing here?

Comments

  • benoit
    benoit Rennes, France
    Hi,

    Did you check if it could be a firewall issue on your Windows 8 machine? It looks like it's not accepting connections on the address 10.0.1.115 and port number 50951.

    You should also make sure your server and client use the right IP address and port number (see this FAQ for tips on how to verify this using network tracing).

    Cheers,
    Benoit.
  • Hi Benoit,

    thanks for your quick reply.

    Firewall on both machines are off. But when I enable network trace on the server it is obvious that on the function call to the client the connection tried to be established points to a port with the localhost address.

    So I treid to configure the Endpoints of my ClientAdapter like this: 'default -h 10.0.1.115'

    But when I do this, I get an runtime assert alert from IncomingConnectionFactory:1632 on the _communicator->createObjectAdapter("ClientAdapter") call.

    Determining the port for the ClientAdpater endpoint works instead...
  • benoit
    benoit Rennes, France
    Hi Markus,

    Thanks, we'll try to reproduce this assert.

    So is it working now after the change? If it's still not working, how did you set the Windows Store App network capabilities in the Visual Studio project? See How to set network capabilities on the Microsoft web site for more information on this.

    Cheers,
    Benoit.
  • Hi Benoit,

    still not working :-(

    I had the capabilities set correctly (Internet Client, Internet Client+Server, Private Network). I also tried it with all capabilitoes (except Document lib) without success.

    I'm using Visual Studio Express 2012 for development.

    Thanks for your effort!

    Greets,
    Markus
  • benoit
    benoit Rennes, France
    Hi Markus,

    Why do you actually configure endpoints for the "ClientAdapter" object adapter in your client?

    According to your code, the object adapter is associated to the client connection (which effectively makes this client connection a "bi-dir" connection). Your client doesn't need to listen on any endpoints if he's using a bi-directional connection to dispatch incoming invocations.

    So you should create the client object adapter with:
    Ice::ObjectAdapterPtr adapter = _communicator->createObjectAdapter("");
    adapter->activate();
    ServerPrx->ice_getConnection()->setAdapter(adapter);
    ...
    

    And remove the following property setting:
    id.properties->setProperty("ClientAdapter.Endpoints", "default");
    

    See the bidir demo from your Ice distribution for an example.

    Cheers,
    Benoit.