× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I made a RPG program calling some Java API below:

Ë     **********************************************************************
      * To Compile:
      *
      *  CRTBNDRPG PGM(xxx/EXOSOCKET) SRCFILE(xxx/QRPGLESRC)
      *
Ë     **********************************************************************
     H DftActGrp(*NO) ActGrp(*CALLER)
      /Copy vhetlib/QRPGLESRC,MATHPR
      /Copy vhetlib/QRPGLESRC,SOCKPR
      /Copy vhetlib/QRPGLESRC,OSTREAMPR
      /Copy vhetlib/QRPGLESRC,ISTREAMPR
     D IPadr           C                   Const('172.23.1.38')
     D Hello           C                   Const('hello\n')
     D Port            S             10I 0
     D tmpIS           S               O  
Class(*JAVA:'java.io.InputStream')
     D tmpOS           S               O  
Class(*JAVA:'java.io.OuputStream')
     D string1         S               O  
Class(*JAVA:'java.lang.String')
     D string2         S               O  
Class(*JAVA:'java.lang.String')
     D Sum             S               O  
Class(*JAVA:'java.math.BigDecimal')
     D BigD1           S               O  
Class(*JAVA:'java.math.BigDecimal')
     D BigD2           S               O  
Class(*JAVA:'java.math.BigDecimal')
     D StringSum       S               O  
Class(*JAVA:'java.lang.String')
     D DisplaySum      S             30A   Varying
      ****************************
     D Sock1           S               O  
Class(*JAVA:'java.net.Socket')
     D is              S               O   Class(*JAVA:
     D                                        
'java.io.InputDataStream')
     D os              S               O   Class(*JAVA:
     D                                        
'java.io.OutputDataStream')
      ****************************
     C                   Eval      String1 = newString(IPadr)
     C                   Eval      String2 = newString(Hello)
     C                   z-add     9999          Port
     C                   Eval      Sock1 = newSocket(String1 : Port)
     C                   Eval      DisplaySum = getBytes(String2)
     C     DisplaySum    Dsply
      /free
       monitor;
        tmpOS=getOutput(Sock1);
        tmpIS=getInput(Sock1);
        os=newOSTREAM(tmpOS);
        is=newISTREAM(tmpIS);
        writeBytes(os : String2);
       on-error *all;

       endmon;
      /end-free
     C*                  Eval      tmpOS = getOutput(Sock1)
     C*                  Eval      tmpIS = getInput(Sock1)
     C*                  Eval      os = newOSTREAM(tmpOS)
     C*                  Eval      is = newISTREAM(tmpIS)
      ****************************
     C*                  CALLP     writeBytes(os : String2)
      ****************************
     C                   CALLP     closeOS(os)
     C                   CALLP     closeIS(is)
     C                   CALLP     closeSocket(Sock1)
     C                   Eval      *InLr = *On


this program of course uses Java prototypes below:

      **********************************************************************
      * getBytes - Converts a string to a byte array for use in a char
field
      **********************************************************************
     D getBytes        PR            30A   ExtProc(*JAVA:
     D                                             'java.lang.String':
     D                                             'getBytes')
     D                                     Varying
      **********************************************************************
      *  newString constructor that accepts a byte array
      *  (an alphnumeric variable in RPG speak). It
      *  returns a string object.
      **********************************************************************
     D newString       PR              O   ExtProc(*JAVA:
     D                                             'java.lang.String':
     D                                             *CONSTRUCTOR)
     D                                    
Class(*JAVA:'java.lang.String')
     D  byes                         30A   Const Varying
      **********************************************************************


      **********************************************************************
     D newSocket       PR              O   ExtProc(*JAVA:
     D                                         'java.net.Socket':
     D                                         *CONSTRUCTOR)
     D                                    
Class(*JAVA:'java.net.Socket')
     D  Host                           O  
Class(*JAVA:'java.lang.String')
     D  PortNumber                   10I 0 VALUE
      **********************************************************************
     D getOutput       PR              O   ExtProc(*JAVA:
     D                                         'java.net.Socket':
     D                                         'getOutputStream')
     D                                    
Class(*JAVA:'java.io.OutputStream')
      **********************************************************************
     D getInput        PR              O   ExtProc(*JAVA:
     D                                         'java.net.Socket':
     D                                         'getInputStream')
     D                                    
Class(*JAVA:'java.io.InputStream')
      **********************************************************************
     D closeSocket     PR                  ExtProc(*JAVA:
     D                                         'java.net.Socket':
     D                                         'close')
      *********************************************************************



     D newOSTREAM      PR              O   ExtProc(*JAVA:
     D                                        
'java.io.DataOutputStream':
     D                                         *CONSTRUCTOR)
     D                                     Class(*JAVA:'java.io.Data+
     D                                      OutputStream')
     D  os                             O  
Class(*JAVA:'java.io.OutputStream')
      **********************************************************************
     D*ISTREAM         PR              O   ExtProc(*JAVA:
     D*                                        'java.io.OutputStream':
     D*                                        *CONSTRUCTOR)
     D*                                    Class(*JAVA:'java.io.Data+
     D*                                     OutputStream')
     D* os                             O  
Class(*JAVA:'java.io.OutputStream')
      **********************************************************************
     D writeBytes      PR                  ExtProc(*JAVA:
     D                                        
'java.io.DataOutputStream':
     D                                         'writeBytes')
     D   ostr                          O  
Class(*JAVA:'java.lang.String')
      **********************************************************************
     D closeOS         PR                  ExtProc(*JAVA:
     D                                        
'java.io.DataOutputStream':
     D                                         'close')
      *********************************************************************


     D newISTREAM      PR              O   ExtProc(*JAVA:
     D                                        
'java.io.DataInputStream':
     D                                         *CONSTRUCTOR)
     D                                     Class(*JAVA:'java.io.Data+
     D                                      InputStream')
     D  os                             O  
Class(*JAVA:'java.io.InputStream ')
      **********************************************************************
     D readLine        PR              O   ExtProc(*JAVA:
     D                                        
'java.io.DataInputStream':
     D                                         'readLine')
     D                                    
Class(*JAVA:'java.lang.String    ')
      **********************************************************************
     D closeIS         PR                  ExtProc(*JAVA:
     D                                        
'java.io.DataInputStream':
     D                                         'close')
      *********************************************************************


Now with this program runs a server program on a remote PC (code below):

import java.io.*;
import java.net.*;

public class echo3 {
    public static void main(String args[]) {

// declaration section:
// declare a server socket and a client socket for the server
// declare an input and an output stream

        ServerSocket echoServer = null;
        String line;
        DataInputStream is;
        PrintStream os;
        Socket clientSocket = null;

// Try to open a server socket on port 9999
// Note that we can't choose a port less than 1023 if we are not
// privileged users (root)

        System.out.println("Server launched\n");

        try {
           echoServer = new ServerSocket(9999);
        }
        catch (IOException e) {
           System.out.println(e);
        }  

// Create a socket object from the ServerSocket to listen and accept
// connections.
// Open input and output streams

try {
           clientSocket = echoServer.accept();
           System.out.println("connected \n");
           is = new DataInputStream(clientSocket.getInputStream());
           os = new PrintStream(clientSocket.getOutputStream());

// As long as we receive data, echo that data back to the client.

           while (true) {
             line = is.readLine();
             os.println(line);
             if(line!=null)
             {
                System.out.println(line);
             }
           }
        }  
catch (IOException e) {
           System.out.println(e);
        }
    }
} 


this program does work.

But I got some errors on eSerie:

Message . . . . :   Application error.  MCH74A5 unmonitored by QJVAJNI at
  statement 0000002709, instruction X'0000'.      

and my RPG program doesn't work while a pure JAVA program running on
the same eSerie works (see below):

import java.io.*;
import java.net.*;

public class smtpClient {
    public static void main(String[] args) {

// declaration section:
// smtpClient: our client socket
// os: output stream
// is: input stream

        Socket Socket1 = null;  
        DataOutputStream os = null;
        DataInputStream is = null;

// Initialization section:
// Try to open a socket on port 9999
// Try to open input and output streams

        try {
            Socket1 = new Socket("172.23.1.38", 9999);
            os = new DataOutputStream(Socket1.getOutputStream());
            is = new DataInputStream(Socket1.getInputStream());
        } catch (UnknownHostException e) {
            System.out.println("Don't know about host: hostname");
        } catch (IOException e) {
            System.out.println("Couldn't get I/O for the connection
to: hostname");
        }


if (Socket1 != null && os != null && is != null) {
            try {

// The capital string before each colon has a special meaning to SMTP
// you may want to read the SMTP specification, RFC1822/3

os.writeBytes("HELO\n");
                os.writeBytes("Hi there\n"); 
                os.writeBytes("ok\n");

// keep on reading from/to the socket till we receive the "Ok",
// once we received that then we want to break.

                String responseLine;
                while ((responseLine = is.readLine()) != null) {
                    System.out.println("Server: " + responseLine);
                    if (responseLine.indexOf("Ok") != -1) {
                      break;
                    }
                }

// clean up:
// close the output stream
// close the input stream
// close the socket

os.close();
                is.close();
                Socket1.close();  
            } catch (UnknownHostException e) {
                System.err.println("Trying to connect to unknown host: " + e);
            } catch (IOException e) {
                System.err.println("IOException:  " + e);
            }
        }
    }          
}                     

If someone has a idea of what is wrong with my program tell me, but
maybe it would first be useful for me to know how I can handled this
exception in order to know where are mistakes.

Thanks for you help.
And sorry for my bad english.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.