I have to send a message over TCP/IP from my program to a server. Below is message format..
struct .recv^msg FIELDALIGN (SHARED2);
I am doing the following...
The method padwithSpaces just adds extra whitespace at the end so that the field size matches what the server needs.
But the above does not seem to be working. The server says message is in wrong format. So any suggestions on what could be wrong?
One concern I had is the first field is " INT(32)" (I think it means it is expecting 32 bit integer). The reason I did not use int is because I thought when Java writes to the output stream it converts to char array. So I just used 2 chars which I hoped would become the 32 bits server is expecting. Am I wrong in this assumption?
Thanks in advance for any help and best regards,
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Joined: Apr 30, 2002
Thanks Winston for cleaning up my post.
I just realized that the first field is 32 bytes and not bits. So I was guessing passing a value like "5555" should translate into that (4 characters is 32 bytes). But it still does not seem to be working.
I doubt that you'd have 32 byte integers. That's 8 times as big as a regular int, and 4 times as big as a long. I think you were right about the 32 bit before.
The problem here is how you try to fill that integer. Just writing a String value of it will not send the integer itself, but its String representation. You send 2 bytes instead of the 4 required. You could check out DataOutputStream:
This may present one problem though - this code writes the integer with the high-byte first (little endian). If the server expects the integer as big endian, you will need to use some bitwise computing to write the integer in reverse order.