aspose file tools*
The moose likes Java in General and the fly likes socket communication with AS400... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "socket communication with AS400..." Watch "socket communication with AS400..." New topic
Author

socket communication with AS400...

Franky John
Greenhorn

Joined: Jan 24, 2011
Posts: 7
Hi,

I am supposed to code an application to talk to AS400... before i send the data i will convert it to "Cp1047" but when it reaches AS400 its appears to in HEX.

Any one can spare me some clue what am i doing wrong here?

Desire result: f0f2f9f9f44040404040f0f0f1f6f6f8f1f6f0f9c3c3f...

Current result: 30323139 30202020 20203032 35313037...

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Welcome to the Ranch!

Can you show us the code you're using to a) convert, and b) send?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Franky John
Greenhorn

Joined: Jan 24, 2011
Posts: 7
Hi there thanks!

Code to convert...



Code to send...

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

What does Arrays.toString(messageValue) return?
Franky John
Greenhorn

Joined: Jan 24, 2011
Posts: 7
print out of Arrays.toString(messageValue)

[-16, -14, -7, -7, -12, 64, 64, 64, 64, 64, -16, -16, -15, -10, -10, -8, -15, -10, -16, -7, -61, -61, -11, -8, -14, -14, -14, -60, -7, -10, -9, -62, 75, -14, -16, -13]
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Franky John wrote:print out of Arrays.toString(messageValue)

[-16, -14, -7, -7, -12, 64, 64, 64, 64, 64, -16, -16, -15, -10, -10, -8, -15, -10, -16, -7, -61, -61, -11, -8, -14, -14, -14, -60, -7, -10, -9, -62, 75, -14, -16, -13]


There is some ambiguity with regards to which computer prints this but if I run :-

then I get

which implies that the result

is nothing to do with the value sent.

:-) Of course it could be that I have the wrong end of the stick!

Note - the values 30323139 30202020 20203032 35313037... look to be just hex encoded ASCII decimal digits and spaces.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

So James showed that the data sent is still the correct data. So I see two possibilities:
1) something goes wrong in sending; unlikely though
2) something goes wrong when receiving

So the next question is, how do you receive the message?
Franky John
Greenhorn

Joined: Jan 24, 2011
Posts: 7
Forgot to mention that its from Window to AS400... and the receiving end is not done me. All i know is that its in C the data sent has to be in EBCDIC
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Franky John wrote:Forgot to mention that its from Window to AS400... and the receiving end is not done me. All i know is that its in C the data sent has to be in EBCDIC

We understood that from the "Cp1047" BUT I don't think that is the whole story. You only need to convert to "Cp1047" if you are sending characters but I suspect that you should actually just be sending bytes without any encoding. Certainly the AS400 values do not look like EBCDIC characters since many have the most significant bit set. Bytes on the AS400 are bytes on Windows are bytes on Linux are bytes on any platform. The "Cp1047" encoding only becomes relevant if those bytes are interpreted as characters and I don't think the values you have posted should be interpreted as characters.

Without you actually posting the sending code we can do little to help you. If you could show both the C on the AS400 and your Java I'm sure I and many others here could help.
Franky John
Greenhorn

Joined: Jan 24, 2011
Posts: 7
I dont have the C code and i cant release the whole piece of coding...

Basically what happen is that i have FUNCTIONX() which returns a String after processing the request.

then pass into a send message function.




James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

You need to print out -

1) The 'Message' string,
2) The hex encoded 'messageValue',
3) The hex encoded 'len'
4) The hex encoded 'temp'.

and post the values.

I don't think you should be getting the OutputStream from the socket each call to sendMessage. I think you should be passing in the OutputStream and writing to that directly.

You don't need the flush() before writing 'temp'. The flush() afterwards is required.

I would be very very very surprised if the hex encoded value of 'temp' looks anything like the value you posted as your required received value in your C code. I think you are sending the wrong data.
Franky John
Greenhorn

Joined: Jan 24, 2011
Posts: 7
Orignal Message 02994 0016681609CC58222D967B.203
Message sent (in EBCDIC) :f0f2f9f9f44040404040f0f0f1f6f6f8f1f6f0f9c3c3f5f8f2f2f2c4f9f6f7c24bf2f0f3...
Overall in hex 0024f0f2f9f9f44040404040f0f0f1f6f6f8f1f6f0f9c3c3f5f8f2f2f2c4f9f6f7c24bf2f0f3...

note: 0024 is the string length and need not be in EBCDIC format but in binary hex
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

The String you are sending (30323139 30202020 20203032 35313037) matches exactly hex encoding of the ASCII characters (02994 0016681609CC58222D967B.203) in your receiver. It looks to me like the value being printed in the received has been converted back to ASCII!. In your position I would talk to the people who wrote the server.
Franky John
Greenhorn

Joined: Jan 24, 2011
Posts: 7
After a week plus of holiday this problem still exists... "LOL" I used to a wireshark to capture the data sent and it appear to be in the right format. Is it right for me to say that what ever the format i am seeing in wireshark once it reaches AS400 it will still be the same?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: socket communication with AS400...