Results 1 to 5 of 5

Thread: Ice::SocketException when using datagram invocation

  1. #1
    joaobertacchi is offline Registered User
    Name: Joao Bertacchi
    Organization: Personal
    Project: Publisher of real time collected data.
    Join Date
    Sep 2011
    Posts
    3

    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?

    Code:
    [ 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.

  2. #2
    bernard's Avatar
    bernard is online now ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    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
    Bernard Normier
    ZeroC, Inc.

  3. #3
    joaobertacchi is offline Registered User
    Name: Joao Bertacchi
    Organization: Personal
    Project: Publisher of real time collected data.
    Join Date
    Sep 2011
    Posts
    3

    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
    Code:
    #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
    Code:
    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!

  4. #4
    benoit's Avatar
    benoit is online now ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    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.

  5. #5
    joaobertacchi is offline Registered User
    Name: Joao Bertacchi
    Organization: Personal
    Project: Publisher of real time collected data.
    Join Date
    Sep 2011
    Posts
    3
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 09-19-2011, 07:35 PM
  2. Replies: 4
    Last Post: 12-14-2010, 05:15 PM
  3. Replies: 3
    Last Post: 10-11-2006, 11:15 PM
  4. getting Ice::SocketException
    By fengqi in forum Help Center
    Replies: 5
    Last Post: 05-10-2006, 08:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •