I am using the following code to connect to a server using a socket.
I have three arguments being sent to the code, the server ip, port and the message.
The code works fine and creates a connection to the server on the specified ip and port but they are not seeing the proper message string.
Since I am using the writeUTF method the string is being converted to Unicode format before the server receives it and it is not able to parse it
properly. Is there a way to see what exactly is being sent throug the socket (out.writeUTF(message)).
Also what would I be using to send the string as it is via the socket. Help much appreciated..
// File Name CallClient.java
This is the string I am passing as an argument,
"00491111206001379TU4I01111111111111 1528Y 02103943PSWD1NEU01Law Office C. SoffarCLVN01ICEware 50169 VIO CD015 TEST SH011NM011ABATE RALPH PI018506690111974082235 AD0124395 COLLECTION LN23 FANTASY ISLAND IL60750 3PN01016232065555 RP0107000N IOD010201001 ENDS011"
The client code you posted works fine on my side. The problem must be on the server side. Just make sure you didn't use something other than DataInputStream.readUTF(), because unlike writeBytes(), writeUTF() adds two extra bytes at the beginning of your data that specify the number of bytes of your data.
Here is the minimal server I used:
As for checking the contents of the data, you can use a free sniffer such as Wireshark and examine the data field of the right TCP segment. Be advised though that capturing packets on the loopback interface under Windows does not work with this tool. But there is a simple workaround that requires adding only a temporary entry in the routing table of your machine: http://forums.whirlpool.net.au/forum-replies-archive.cfm/1037087.html
Your call to in.readLine() will block until the server actually sends a string terminated with a newline character. There might be several reasons why the server doesn't send this newline character, but it is quite plausible that it is waiting for extra input from your client, or that it is confused because it didn't receive the data it was expecting and in the correct order. It may as well be that the server doesn't even intend to send a newline character to indicate the end of the data it sends you.
I may be wrong, but I think the main issue here is that you and the server are not "speaking the same language". You have to figure out exactly what the server is expecting from your client and in what format. For instance, perhaps the server is expecting that you insert some kind of delimiters between the different data elements you are sending? Or that you have to include the size of the data you are sending? Otherwise, it can be hard for the server to determine if all the necessary data has arrived and that it should start interpreting it.
Hopefully I am pointing you in the right direction...