Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-19-2008, 09:11 PM
Member
 
Join Date: Mar 2008
Posts: 3
cheongww is on a distinguished road
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");
}
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-19-2008, 09:43 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-20-2008, 05:38 AM
Member
 
Join Date: Mar 2008
Posts: 3
cheongww is on a distinguished road
hi there... sorry that I didnt put the codes properly

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"); } } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-02-2008, 12:29 PM
Member
 
Join Date: Oct 2008
Posts: 1
hhibm01 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-02-2008, 08:32 PM
Member
 
Join Date: Mar 2008
Posts: 3
cheongww is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set a max response time in webservice client sudheerbasu.k@gmail.com Advanced Java 1 05-11-2008 04:25 AM
Finding out the client who is receiving the response. v.ranjith Advanced Java 2 01-29-2008 09:03 AM
Identify Client in Socket Client Server Application masadjie Networking 1 12-20-2007 11:18 AM
Socket Programming (Client) JavaForums Java Blogs 0 11-26-2007 06:00 PM
socket Multithreading - & - Obtaining the IP of a client! bluebarca Networking 1 11-16-2007 12:09 PM


All times are GMT +3. The time now is 03:06 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org