Archived

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

Ice::SocketException when using datagram invocation

Hi,

I'd like to use Ice datagram invocation to send updated data from a sensor to a server. In my application, only the most updated sensor data is important. That's why I decided for using udp instead of tcp.

I thought all datagram invocation would be successfully run, but when there is no socket listening to udp connections in the defined port a SocketException is thrown. This shouldn't be a problem if I catch it, but even doing so, after some time the client crashes. It seems to be some connection timeout. Could you, please, help me to make my client keeps on trying to send data indefinitely even when a server is not available?
[ 09/27/11 15:55:35.064 Network: starting to send udp packets
  local address = 127.0.0.1:53383
  remote address = 127.0.0.1:10001 ]
[ 09/27/11 15:55:36.084 Network: closing udp connection
  local address = 127.0.0.1:53383
  remote address = 127.0.0.1:10001 ]
UdpTransceiver.cpp:202: Ice::SocketException:
socket exception: Connection refused

Thanks,
João.

Comments

  • bernard
    bernard Jupiter, FL
    Hi João,

    Welcome to our forums!

    It would be helpful to specify the Ice version you're using, your operating system and programming language / compiler.

    Can you also post a small client program that can be used to reproduce this problem?

    Best regards,
    Bernard
  • System information

    Hi Bernard,

    I'm using the following configuration:
    OS: Ubuntu 11.04 32bits
    Compiler: g++-4.4.3-1ubuntu1
    ICE version: zeroc-ice-3.3.1-12

    The program bellow was based on the PrintServer hello world.

    Client.cpp
    #include <Ice/Ice.h>
    #include <UnitManager.h>
    
    using namespace std;
    using namespace Demo;
    
    int
    main(int argc, char* argv[])
    {
        int status = 0;
        Ice::CommunicatorPtr ic;
        UnitDynamicModel unit;
        unit.id = "joao";
        unit.timestamp = 0.0;
        unit.latitude = 0.0;
        unit.longitude = 0.0;
        unit.height = 1000;
        unit.altitude = 200;
        unit.heading = 0.0;
        unit.speed = 23.0;
        unit.status = available;
    
        try {
            ic = Ice::initialize(argc, argv);
            Ice::ObjectPrx base = ic->stringToProxy("MyUnitManager:udp -p 10001 -z");
    
    
            // Get a datagram proxy.
            //
            Ice::ObjectPrx datagram = base->ice_batchDatagram()->ice_compress(true);
            //Ice::ObjectPrx datagram = base->ice_batchDatagram();
            //Ice::ObjectPrx datagram = base->ice_datagram();
    
    
            UnitManagerPrx unitManager = UnitManagerPrx::uncheckedCast(datagram);
            if (!unitManager)
                throw "Invalid proxy";
    
            while (1) {
    			for (int i=0; i<200; i++){
    				unit.timestamp = i;
    				unit.latitude += i;
    				unit.longitude += i + 2;
    				unit.height += i + 10;
    				unit.altitude += i + 20;
    				unit.heading = i % 360;
    				unit.speed += i;
    				unitManager->update(unit);
    			}
    			unitManager->ice_flushBatchRequests();
    			sleep(1);
            }
        } catch (const char* msg) {
            cerr << msg << endl;
            status = 1;
        } catch (const Ice::NoEndpointException& e) {
            cerr << "No endpoint for datagram invocations: " << e.proxy << endl;
        } catch (const Ice::TwowayOnlyException&) {
            cerr << "printString() is not oneway" << endl;
        } catch (const Ice::Exception& ex) {
                cerr << ex << endl;
                status = 1;
        }
        if (ic)
            ic->destroy();
        return status;
    }
    

    UnitManager.ice
    module Demo {
    	enum UnitStatus {available, designated, unavailable};
    	
        struct UnitDynamicModel {
    		string id; // unit name identification
    		long seq_num; // sequence number
    		double latitude; //�degrees
    		double longitude; //�degrees
    		int height;	// meters
    		int altitude;	// meters
    		float heading;	// degrees
    		float speed;	//�km/h
    		UnitStatus status;	// enum
    	};
    	
        interface UnitManager {
            idempotent void update(UnitDynamicModel unit);
        };
    };
    

    Thanks for helping!
  • benoit
    benoit Rennes, France
    Hi,

    Even if you had to catch the exception, it shouldn't crash. Any chance you could try with Ice 3.4.2 instead? If it still fails with Ice 3.4.2, could you send us the stack trace of the crash?

    Cheers,
    Benoit.
  • Hi benoit,

    After cleaning the build environment I couldn't reproduce this problem (exceptions are thrown but the program doesn't crash anymore). When the can reproduce this issue again I contact you.

    Thanks