aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ic/examples/java-client-server
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ic/examples/java-client-server')
-rw-r--r--lib/ic/examples/java-client-server/ReadMe69
-rw-r--r--lib/ic/examples/java-client-server/client.java60
-rw-r--r--lib/ic/examples/java-client-server/random.idl49
-rw-r--r--lib/ic/examples/java-client-server/server.java82
-rw-r--r--lib/ic/examples/java-client-server/serverImpl.java42
5 files changed, 302 insertions, 0 deletions
diff --git a/lib/ic/examples/java-client-server/ReadMe b/lib/ic/examples/java-client-server/ReadMe
new file mode 100644
index 0000000000..9fde464e09
--- /dev/null
+++ b/lib/ic/examples/java-client-server/ReadMe
@@ -0,0 +1,69 @@
+This is a short description on the use of the java demo,
+a client that initiates and uses a random number generator
+that lies on a java-server. You will be able to shift the
+existing client/server with the ones refered to the other
+examples.
+
+Instructions.
+
+1) Start erlang
+
+ On the erlang shell type :
+ --------------------------
+
+ ic:gen(random,[{be,java}]). ( generates the java code )
+
+
+2) Modify the "SNode" string on file "server.java" to the server
+ node name thet suites for your machine.
+
+
+3) Modify the "SNode" string on file "client.java" to the client
+ node for your machine and the "PNode" string for the server
+ node ( = the same as the SNode for the "server.java" file ).
+
+
+4) Set and export the CLASSPATH variable to point to the
+ java classes located in java development kit, the
+ Otp's classes and the current directory.
+ Your classpath should look like this :
+
+ .:<OTPROOT>/lib/ic-4.0/priv/ic.jar:<OTPROOT>/lib/jinterface_1.1/priv/OtpErlang.jar
+
+ where :
+
+ <OTPROOT> is the location there OTP is installed
+
+
+5) Start the empd deamon by using the command :
+
+ epmd -daemon
+
+
+6) Compile the generated java code :
+
+ javac rmod/*.java ( compiles all generated java code )
+
+ javac *.java ( compiles all manually writen java code )
+
+
+7) Start the java on an terminal window :
+
+ java server ( starts the java-server )
+
+
+8) Start the client on an terminal window :
+
+ java client ( calls the server )
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/ic/examples/java-client-server/client.java b/lib/ic/examples/java-client-server/client.java
new file mode 100644
index 0000000000..4dc88cffbb
--- /dev/null
+++ b/lib/ic/examples/java-client-server/client.java
@@ -0,0 +1,60 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-2009. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ *
+ */
+public class client {
+
+ private static java.lang.String SNode = "client";
+ private static java.lang.String PNode = "babbis";
+ private static java.lang.String Cookie = "flash";
+ private static java.lang.String Server = "rmod_random_impl";
+
+ private static rmod._randomStub stub;
+
+ public static void main(String[] args) {
+
+ try {
+
+ stub = new rmod._randomStub(SNode,PNode,Cookie,Server);
+ int seed1 = 1;
+ int seed2 = 2;
+ int seed3 = 3;
+ double random = 0;
+
+ System.out.print("\nClient initialization....");
+ stub.init(seed1,seed2,seed3);
+ System.out.println("ok\n");
+
+
+ for (int i = 0; i < 10; i++) {
+ random = stub.produce();
+ System.out.println("Random" + i + " = " + random);
+ }
+ System.out.println("\nClient terminated.\n");
+
+ stub.__disconnect();
+
+ } catch( Exception e) {
+ System.out.println("Exception :");
+ e.printStackTrace();
+ }
+
+ }
+
+}
+
diff --git a/lib/ic/examples/java-client-server/random.idl b/lib/ic/examples/java-client-server/random.idl
new file mode 100644
index 0000000000..b2c21bdbfd
--- /dev/null
+++ b/lib/ic/examples/java-client-server/random.idl
@@ -0,0 +1,49 @@
+// ``The contents of this file are subject to the Erlang Public License,
+// Version 1.1, (the "License"); you may not use this file except in
+// compliance with the License. You should have received a copy of the
+// Erlang Public License along with this software. If not, it can be
+// retrieved via the world wide web at http://www.erlang.org/.
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+// the License for the specific language governing rights and limitations
+// under the License.
+//
+// The Initial Developer of the Original Code is Ericsson Utvecklings AB.
+// Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
+// AB. All Rights Reserved.''
+//
+// $Id$
+//
+
+#ifndef _RANDOM_IDL
+#define _RANDOM_IDL
+
+module rmod {
+
+ interface random {
+
+ double produce();
+
+ oneway void init(in long seed1, in long seed2, in long seed3);
+
+ };
+
+};
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/ic/examples/java-client-server/server.java b/lib/ic/examples/java-client-server/server.java
new file mode 100644
index 0000000000..6b5fe8fcfd
--- /dev/null
+++ b/lib/ic/examples/java-client-server/server.java
@@ -0,0 +1,82 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-2009. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ *
+ */
+public class server {
+
+ private static java.lang.String SNode = "babbis";
+ private static java.lang.String Cookie = "flash";
+ private static java.lang.String RegName = "rmod_random_impl";
+
+ public static void main(String[] args) {
+
+
+ System.out.println("\nServer running.\n");
+ boolean serverState = true;
+ boolean recState = true;
+
+ try {
+
+ com.ericsson.otp.erlang.OtpServer self = new com.ericsson.otp.erlang.OtpServer(SNode, Cookie);
+ self.publishPort();
+
+ /* Server loop */
+ while(serverState == true) {
+
+ com.ericsson.otp.erlang.OtpConnection connection = self.accept();
+ serverImpl srv = new serverImpl();
+ com.ericsson.otp.erlang.OtpInputStream request;
+ com.ericsson.otp.erlang.OtpOutputStream reply;
+ com.ericsson.otp.erlang.OtpErlangPid client;
+
+ /* Server loop */
+ while(recState == true) {
+
+ if (connection.isConnected() == true)
+ try {
+
+ request = connection.receiveBuf();
+
+ reply = srv.invoke(request);
+
+ if (reply != null) {
+ client = srv.__getCallerPid();
+
+ connection.sendBuf(client,reply);
+ }
+
+ } catch( Exception e) {
+ System.out.println("Server terminated.\n\n");
+ recState = false;
+ serverState = false;
+ }
+ }
+
+ connection.close();
+ }
+
+ } catch( Exception e) {
+ System.out.println("Initialization exception :");
+ e.printStackTrace();
+ }
+ }
+}
+
+
+
+
diff --git a/lib/ic/examples/java-client-server/serverImpl.java b/lib/ic/examples/java-client-server/serverImpl.java
new file mode 100644
index 0000000000..d5fb66e96b
--- /dev/null
+++ b/lib/ic/examples/java-client-server/serverImpl.java
@@ -0,0 +1,42 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-2009. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ *
+ */
+public class serverImpl extends rmod._randomImplBase {
+
+ java.util.Random random = null;
+
+
+ public void init(int seed1, int seed2, int seed3) throws java.lang.Exception {
+
+ random = new java.util.Random(seed1+seed2+seed3);
+ };
+
+
+ public double produce() throws java.lang.Exception {
+
+ return random.nextDouble();
+ }
+
+}
+
+
+
+
+
+