Results 1 to 2 of 2

Thread: Android Server

  1. #1
    Daniel_Kim is offline Registered User
    Name: Daniel Kim
    Organization: UC Berkeley
    Project: Android to Android Client Server Communication
    Join Date
    Dec 2010
    Posts
    1

    Android Server

    Hello,

    I am a student from UC Berkeley and I was wondering if it was possible to have an android server. And if so, do you have any example code that I can look at?

    Thank you very much
    Daniel

  2. #2
    adam3914 is offline Registered User
    Name: Adam Kalb
    Organization: University of Rochester Laser labs
    Project: Remote Image Acquisition
    Join Date
    Oct 2008
    Posts
    6
    here is a simple server i made using the basic printer example in the ice manual that displays a notification when a new message is received. Im not sure how to run it on the emulator, because I don't know what host name to give to the client. I just run it on my phone using my wireless home network. Then use the local ip address of the phone as the host name.

    Android Server
    Code:
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.Build.VERSION;
    import Demo._PrinterDisp;
    import Ice.Current;
    import android.content.Context;
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    
    public class helloServer extends Activity {
        /** Called when the activity is first created. */
    	Ice.Communicator ic=null;
    	Demo.PrinterPrx printer;
    	Ice.Object object = new PrinterI();
    	
        @Override
        public void onCreate(Bundle savedInstanceState) {
        	if(VERSION.SDK_INT == 8) // android.os.Build.VERSION_CODES.FROYO (8)
            {
                //
                // Workaround for a bug in Android 2.2 (Froyo).
                //
                // See http://code.google.com/p/android/issues/detail?id=9431
                //
                java.lang.System.setProperty("java.net.preferIPv4Stack", "true");
                java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
            }
            super.onCreate(savedInstanceState);
            if(ic==null){
            Ice.Properties props = Ice.Util.createProperties();
            Ice.InitializationData id = new Ice.InitializationData();
            id.properties=props;
            ic=Ice.Util.initialize(id);
            
            Ice.ObjectAdapter adapter=ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000");
            adapter.add(object, ic.stringToIdentity("SimplePrinterAdapter"));
            adapter.activate();
            }
    
        }
        public class PrinterI extends _PrinterDisp {
    
    	public PrinterI() {
    		
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	public void printString(String s, Current __current) {
    		// TODO Auto-generated method stub
    		NotificationManager notifier = (NotificationManager)helloServer.this.getSystemService(Context.NOTIFICATION_SERVICE);
    		Notification notification = new Notification(1,"Notification",System.currentTimeMillis());
    		Intent toLaunch = new Intent(helloServer.this,helloServer.class);
    		PendingIntent contentIntent =PendingIntent.getActivity(helloServer.this, 0, toLaunch, 0);
    		notification.setLatestEventInfo(helloServer.this,s,"" , contentIntent);
    		notification.flags |= Notification.FLAG_AUTO_CANCEL;
    		notification.flags |= Notification.DEFAULT_SOUND;
    		//Send the notification
    		notifier.notify(0x007, notification);
    	}
    
    }
        
        @Override
        public void onDestroy(){
        	super.onDestroy();
        	//ic.destroy();
        }
        @Override
        public void onPause(){
        	super.onDestroy();
        }
    
    }
    c++ client

    Code:
    #include <Ice/Ice.h>
    #include <Printer.h>
    
    using namespace std;
    using namespace Demo;
    
    
    int
    main(int argc, char* argv[])
    {
        int status = 0;
        Ice::CommunicatorPtr ic;
        try {
           ic = Ice::initialize(argc, argv);
    
    		Ice::ObjectPrx base=ic->stringToProxy("SimplePrinterAdapter:tcp -h 192.168.1.105 -p 10000");
    		PrinterPrx printer=PrinterPrx::checkedCast(base);
    		printer->printString("test");
    
        } catch (const Ice::Exception& e) {
            cerr << e << endl;
            status = 1;
        } catch (const char* msg) {
            cerr << msg << endl;
            status = 1;
        }
        if (ic) {
            try {
    			ic->destroy();
            } catch (const Ice::Exception& e) {
                cerr << e << endl;
                status = 1;
            }
        }
        return status;
    }

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Ice for Android 0.2.0 released
    By mes in forum Announcements
    Replies: 0
    Last Post: 02-08-2011, 04:32 PM
  2. Cannot get IceStorm working on Android
    By AlexBell in forum Help Center
    Replies: 1
    Last Post: 01-03-2011, 08:30 AM
  3. Servant on Android device
    By JoseLSegura in forum Help Center
    Replies: 8
    Last Post: 04-20-2010, 09:40 AM
  4. Replies: 1
    Last Post: 04-20-2010, 03:32 AM
  5. Replies: 4
    Last Post: 03-24-2010, 01:35 PM

Posting Permissions

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