I am trying to send a string through sockets but I just have some problems. the string that I am trying to send is ; (ATTENTION : It is a string NOT XML )
<message>
<header>
<messageType>snmp</messageType>
<sendFrom>192.168.0.16</sendFrom>
<hostName>oghmasysMehmet</hostName>
<sendTo>192.168.0.12</sendTo>
<receiverName>Mehmet</receiverName>
<date>03/10/2011</date>
</header>
<body>
<snmpType>getbulk</snmpType>
<ip>127.0.0.1</ip>
<port>161</port>
<oids>
<oid>1.3.6.1.2.1.1.3.0</oid>
</oids>
<community>community</community>
<nR>0</nR>
<mR>5</mR>
</body>
</message>
But when I look what I get from server it is just ;
<?xml version="1.0" encoding="UTF-8"?>
I dont know what is the problem:
I am using ,
socket = new Socket(localIP, Integer.parseInt(localPort));
out = new PrintWriter(socket.getOutputStream(), true);
to send the string from client and use,
in = new BufferedReader(new InputStreamReader(client.getInputStream()));
line = in.readLine();
to read the string on server.
Can you please help me how I can solve it ?
Thank you all
Lucas has the answer, I believe. Personally, I don’t trust readLine() as in doing so is making the assumption that you are recv-ing valid String data on the socket…. which is a very poor assumption!
Try reading into a byte buffer first, then try to make it into a string:
…Now, my example has a few issues to it, but the point (should) be made =D