Results 1 to 5 of 5
  1. #1
    cheongww is offline Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0

    Question Problem with Socket Client - Intermittent Truncated Response in AIX

    Hi guru

    I have written on Socket Client method below to send request byte[] to Host and receive response byte[] from Host.
    For this particular response, I'm expecting Host to return me byte[] with length 2274.
    My problem is intermittently I received truncated message byte[] from Host with length only 1392. Sometimes I received full 2274 message, sometimes I received 1392 length. I tested in continual of 10 times by sending the same request to host, intermittently received truncated response message.

    My real problem is that this only happened in AIX machine. With the same class, I tested on Windows platform and i received full response message byte[] with 2274 lenght always. Therefore, im counting out the possibilities that Host might send me truncated message.

    Can anyone pls help to tell me how should I proceed to troubleshoot this problem in AIX? Is possible for me to trace what coming in?

    [I] public byte[] sendToHost(byte[] requestMessage, String requestId, String localTxnCode) throws Exception {
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    long startTime = 0;
    long elapsed = 0;
    try {
    LogManager.log(LogManager.DEBUG, Constants.DEFAULT_LOGGER_NAME, requestId, "[" + localTxnCode + "] To connect and send message to Host hostAddr=[" + hostAddr + "], hostPort=[" + hostPort
    + "]");
    startTime = System.currentTimeMillis();
    hostSocket = new Socket(InetAddress.getByName(hostAddr), hostPort);
    hostSocket.setSoTimeout(timeOut);
    byte responseData[] = new byte[4096];
    bis = new BufferedInputStream(hostSocket.getInputStream());
    bos = new BufferedOutputStream(hostSocket.getOutputStream()) ;
    bos.write(requestMessage);
    bos.flush();
    int length = bis.read(responseData);
    elapsed = System.currentTimeMillis() - startTime;
    ARBAdapterUtil.log(LogManager.DEBUG, Constants.DEFAULT_LOGGER_NAME, requestId, "[" + localTxnCode + "] Received message from Host length=[" + length + "]");
    // The response byte must not be 4096 everytime
    byte[] returnByte = new byte[length];
    for (int i = 0; i < length; i++) {
    returnByte[i] = responseData;
    }
    return returnByte;
    } catch (BindException b) {
    elapsed = System.currentTimeMillis() - startTime;
    throw new SocketException("Socket Exception: BindException IP=" + hostAddr + " PORT=" + hostPort + " Error type=" + b.getClass().getName() + " Error message=" + b.getMessage());
    } catch (ConnectException c) {
    elapsed = System.currentTimeMillis() - startTime;
    throw new SocketException("Socket Exception: ConnectException IP=" + hostAddr + " PORT=" + hostPort + " Error type=" + c.getClass().getName() + " Error message=" + c.getMessage());
    } catch (NoRouteToHostException nrth) {
    elapsed = System.currentTimeMillis() - startTime;
    throw new SocketException("Socket Exception: NoRouteToHostException IP=" + hostAddr + " PORT=" + hostPort + " Error type=" + nrth.getClass().getName() + " Error message="
    + nrth.getMessage());
    } catch (SocketTimeoutException se) {
    elapsed = System.currentTimeMillis() - startTime;
    throw new SocketTimeoutException("Socket Exception: SocketTimeoutException IP=" + hostAddr + " PORT=" + hostPort + " Error type=" + se.getClass().getName() + " Error message=" + se.getMessage());
    } catch (SocketException s) {
    elapsed = System.currentTimeMillis() - startTime;
    throw new SocketException("Socket Exception: SocketException IP=" + hostAddr + " PORT=" + hostPort + " Error type=" + s.getClass().getName() + " Error message=" + s.getMessage());
    } catch (Exception e) {
    elapsed = System.currentTimeMillis() - startTime;
    throw new Exception("Unknown Exception: Exception IP=" + hostAddr + " PORT=" + hostPort + "Error type=" + e.getClass().getName() + " Error message=" + e.getMessage());
    } finally {
    try {
    ARBAdapterUtil.log(LogManager.INFO, Constants.DEFAULT_LOGGER_NAME, requestId, "ARBConnection.sendToHost() [" + localTxnCode + "] Time Elapsed via Socket in millisecond = [" + elapsed + "]");
    if (bis != null) {
    bis.close();
    bis = null;
    }
    if (bos != null) {
    bos.close();
    bos = null;
    }
    } catch (Exception e) {
    LogManager.log(LogManager.ERROR, Constants.DEFAULT_LOGGER_NAME, requestId, "ARBConnection.sendToHost() [" + localTxnCode + "] Exception during closing BufferedInputStream and BufferedOutputStream");
    }
    }
    }

  2. #2
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    Could you for the love of god post it in code brackets. My mind almost imploded on itself just looking at that.
    My IP address is 127.0.0.1

  3. #3
    cheongww is offline Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0

    Default

    hi there... sorry that I didnt put the codes properly

    Java Code:
        public byte[] sendToHost(byte[] requestMessage, String requestId, String localTxnCode) throws Exception {
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            long startTime = 0;
            long elapsed = 0;
            try {
                LogManager.log(LogManager.DEBUG, Constants.DEFAULT_LOGGER_NAME, requestId, "[" + localTxnCode + "] To connect and send message to Host hostAddr=[" + hostAddr + "], hostPort=[" + hostPort
                        + "]");
                startTime = System.currentTimeMillis();
                hostSocket = new Socket(InetAddress.getByName(hostAddr), hostPort);
                hostSocket.setSoTimeout(timeOut);
                byte responseData[] = new byte[4096];
                bis = new BufferedInputStream(hostSocket.getInputStream());
                bos = new BufferedOutputStream(hostSocket.getOutputStream());
                bos.write(requestMessage);
                bos.flush();
                int length = bis.read(responseData);
                elapsed = System.currentTimeMillis() - startTime;
                ARBAdapterUtil.log(LogManager.DEBUG, Constants.DEFAULT_LOGGER_NAME, requestId, "[" + localTxnCode + "] Received message from Host length=[" + length + "]");
                // The response byte must not be 4096 everytime
                byte[] returnByte = new byte[length];
                for (int i = 0; i < length; i++) {
                    returnByte[i] = responseData[i];
                }
                return returnByte;
            } catch (BindException b) {
                elapsed = System.currentTimeMillis() - startTime;
                throw new SocketException("Socket Exception: BindException IP=" + hostAddr + " PORT=" + hostPort + "  Error type=" + b.getClass().getName() + " Error message=" + b.getMessage());
            } catch (ConnectException c) {
                elapsed = System.currentTimeMillis() - startTime;
                throw new SocketException("Socket Exception: ConnectException IP=" + hostAddr + " PORT=" + hostPort + "  Error type=" + c.getClass().getName() + " Error message=" + c.getMessage());
            } catch (NoRouteToHostException nrth) {
                elapsed = System.currentTimeMillis() - startTime;
                throw new SocketException("Socket Exception: NoRouteToHostException IP=" + hostAddr + " PORT=" + hostPort + "  Error type=" + nrth.getClass().getName() + " Error message="
                        + nrth.getMessage());
            } catch (SocketTimeoutException se) {
                elapsed = System.currentTimeMillis() - startTime;
                throw new SocketTimeoutException("Socket Exception: SocketTimeoutException IP=" + hostAddr + " PORT=" + hostPort + "  Error type=" + se.getClass().getName() + " Error message=" + se.getMessage());
            } catch (SocketException s) {
                elapsed = System.currentTimeMillis() - startTime;
                throw new SocketException("Socket Exception: SocketException IP=" + hostAddr + " PORT=" + hostPort + "  Error type=" + s.getClass().getName() + " Error message=" + s.getMessage());
            } catch (Exception e) {
                elapsed = System.currentTimeMillis() - startTime;
                throw new Exception("Unknown Exception: Exception IP=" + hostAddr + " PORT=" + hostPort + "Error type=" + e.getClass().getName() + " Error message=" + e.getMessage());
            } finally {
                try {
                    ARBAdapterUtil.log(LogManager.INFO, Constants.DEFAULT_LOGGER_NAME, requestId, "ARBConnection.sendToHost() [" + localTxnCode + "] Time Elapsed via Socket in millisecond = [" + elapsed + "]");
                    if (bis != null) {
                        bis.close();
                        bis = null;
                    }
                    if (bos != null) {
                        bos.close();
                        bos = null;
                    }
                } catch (Exception e) {
                    LogManager.log(LogManager.ERROR, Constants.DEFAULT_LOGGER_NAME, requestId, "ARBConnection.sendToHost() [" + localTxnCode + "] Exception during closing BufferedInputStream and BufferedOutputStream");
                }
            }
        }

  4. #4
    hhibm01 is offline Member
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Default same problem on AIX

    Hello cheongww,
    i have the same problem on AIX. Have you get a solution for your problem ?
    If yes, please can you tell, which kind of correction i have to install.

    best regards, hhibm01.

  5. #5
    cheongww is offline Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0

    Default same problem on AIX

    Hi

    The root cause that we found out is actually nothing to do with application.
    It is actually the Host End which is As400. According to my system ppl, there's one setting in As400 that controls the number of byte of stream. After they changed that, it worked.

    Hope that this can do u some help.

Similar Threads

  1. How to set a max response time in webservice client
    By sudheerbasu.k@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 05-11-2008, 02:25 AM
  2. Finding out the client who is receiving the response.
    By v.ranjith in forum Advanced Java
    Replies: 2
    Last Post: 01-29-2008, 07:03 AM
  3. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 09:18 AM
  4. Replies: 1
    Last Post: 11-16-2007, 10:09 AM

Posting Permissions

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