db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

How to use Java db4o server and .net CF db4o client?

Last post 11-22-2008, 11:28 AM by blackspear. 2 replies.
Sort Posts: Previous Next
  •  11-20-2008, 06:55 PM 52101

    How to use Java db4o server and .net CF db4o client?

    Hi All

    I have an Java server and a .net client:

     Connecting works fine, but when I try to save an object and open the file with the Objectmanager, I can see no stored objects. What is wrong with my code? Please support me in solving the issue,am struggling for quite a long time now :)... 

    Server:

    import java.io.*;
    import com.db4o.*;

    public class RunServer implements Runnable {
        private boolean stop = false;

        public void run() {
            synchronized (this) {
                ObjectServer server = Db4o.openServer("c:/netserver.yap", 8732);
                server.grantAccess("user1", "password");
                server.grantAccess("user2", "password");

                try {
                    // stop condition will be defined in a later example
                    while (!stop) {
                        System.out.println("SERVER:[" + System.currentTimeMillis()
                                + "] Server's running... ");
                        this.wait(60000);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    server.close();
                }
            }
        }
       
        public static void main(String[] args) {
            Thread s = new Thread(new RunServer(),"server");
           
            s.setPriority(Thread.MAX_PRIORITY);
            s.start();
           

        }
    }

     

    Client:

     using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using com.db4o;
    using System.IO;
    using Db4objects.Db4o;
    using System.Threading;

    namespace com.db4o.dg2db4o.chapter8
    {
        public partial class AddClient : Form
        {
            private Db4objects.Db4o.IObjectContainer aClient;
            private bool stop = false;

            public AddClient()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
               
                aClient = Db4objects.Db4o.Db4oFactory.OpenClient("192.168.1.3", 8732, "user1", "password");
              
                   // label1.Text="ADDCLIENT: Please enter a name: ";
                  //  String name = textBox1.Text;
                   // label2.Text="ADDCLIENT: Please enter an age: ";
                   // int age = Convert.ToInt32(textBox2.Text);
                    aClient.Set(new Person("abc", 32));
                    aClient.Commit();
               
             //   aClient.Close();
                MessageBox.Show("Done");
            }

          
        }
    }

     

     

    Filed under: ,
  •  11-21-2008, 07:32 PM 52117 in reply to 52101

    Re: How to use Java db4o server and .net CF db4o client?

    Hi,

    I have not tried that but it should work (with some limitations).

    Please, take a look in

    http://developer.db4o.com/Resources/view.aspx/Reference/Implementation_Strategies/Aliases

    and also in

    db4o.net/Db4objects.Db4o.Tests/native/Db4objects.Db4o.Tests/CLI1/CrossPlatform/JavaServerCrossplatformTestCase.cs

    and let me know if that helped you.

    Adriano

    blackspear wrote:
    > Hi All
    >
    > I have an Java server and a .net client:
    >
    > Connecting works fine, but when I try to save an object and open the
    > file with the Objectmanager, I can see no stored objects. What is wrong
    > with my code? Please support me in solving the issue,am struggling for
    > quite a long time now :)...
    >
    > Server:
    >
    > import java.io.*;
    > import com.db4o.*;
    >
    > public class RunServer implements Runnable {
    > private boolean stop = false;
    >
    > public void run() {
    > synchronized (this) {
    > ObjectServer server = Db4o.openServer("c:/netserver.yap", 8732);
    > server.grantAccess("user1", "password");
    > server.grantAccess("user2", "password");
    >
    > try {
    > // stop condition will be defined in a later example
    > while (!stop) {
    > System.out.println("SERVER:[" +
    > System.currentTimeMillis()
    > + "] Server's running... ");
    > this.wait(60000);
    > }
    > } catch (Exception e) {
    > e.printStackTrace();
    > } finally {
    > server.close();
    > }
    > }
    > }
    >
    > public static void main(String[] args) {
    > Thread s = new Thread(new RunServer(),"server");
    >
    > s.setPriority(Thread.MAX_PRIORITY);
    > s.start();
    >
    >
    > }
    > }
    >
    >
    >
    > Client:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.ComponentModel;
    > using System.Data;
    > using System.Drawing;
    > using System.Text;
    > using System.Windows.Forms;
    > using com.db4o;
    > using System.IO;
    > using Db4objects.Db4o;
    > using System.Threading;
    >
    > namespace com.db4o.dg2db4o.chapter8
    > {
    > public partial class AddClient : Form
    > {
    > private Db4objects.Db4o.IObjectContainer aClient;
    > private bool stop = false;
    >
    > public AddClient()
    > {
    > InitializeComponent();
    > }
    >
    > private void button1_Click(object sender, EventArgs e)
    > {
    >
    > aClient =
    > Db4objects.Db4o.Db4oFactory.OpenClient("192.168.1.3", 8732, "user1",
    > "password");
    >
    > // label1.Text="ADDCLIENT: Please enter a name: ";
    > // String name = textBox1.Text;
    > // label2.Text="ADDCLIENT: Please enter an age: ";
    > // int age = Convert.ToInt32(textBox2.Text);
    > aClient.Set(new Person("abc", 32));
    > aClient.Commit();
    >
    > // aClient.Close();
    > MessageBox.Show("Done");
    > }
    >
    >
    > }
    > }
    >
    >
    >
    >
    >
    >
    > ------------------------------------------------------------------------
    > http://developer.db4o.com/forums/thread/52101.aspx
    >
  •  11-22-2008, 11:28 AM 52124 in reply to 52117

    Re: How to use Java db4o server and .net CF db4o client?

    Dear Sir

    Thanks for the reply...Iam struggling to work out the solution...

     It will be really useful if you can attach a hello world  solution which does the data replication between a  .net CF application and either java or .net server running in PC. Finally I would like to read the db4o database in the PC using a java code.

    I have tried using the Alias Sample in the resources column, but still facing issues in reading the objects...

     Your help will be highly appreciated.

     Thanks once again,

    Blackspear

     

View as RSS news feed in XML