This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

socket communication with AS400...

 
Franky John
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Can you show us the code you're using to a) convert, and b) send?
 
Franky John
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there thanks!

Code to convert...



Code to send...

 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does Arrays.toString(messageValue) return?
 
Franky John
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic