I need to send a Message Header plus "\r\n\r\n" plus Message Body (similar
to HTTP header and body) through socket from a TCP client. The TCP server
listen to the port and after it get message header, it will get the length
of body from the header and read the stream again so it can get the body.
The client can always read header message successfully. However, the client
usually cannot get the FULL body message successfully. How should I do?

Here is the code for sending message:
void func1(String strInputUrl)
{

//prepare sample data
String strOutput="";
String strHttpBody=
"\r\n"+
" \r\n"+
" 18\r\n"+
" \r\n"+
"\r\n\r\n";

int ii=strHttpBody.length();
String strtmp=Integer.toString(ii);

String strHttpHeader=
"NOTIFY ninja HTTP/1.0\r\n"+
"Content-Type: text/plain\r\n"+
"Content-Length: "+strtmp+"\r\n"+
"NT: upnp:event\r\n"+
"NTS: upnpropchange\r\n"+
"SID: 12345678\r\n"+
"SEQ: 1\r\n"+
"User-Agent: Java1.3.0\r\n"+
"Host: ninja:8001\r\n"+
"Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"+
"Connection: keep-alive\r\n\r\n";

strOutput=strHttpHeader+strHttpBody;

//send data
try
{
URL u=new URL(strInputUrl);

Socket s=new Socket(u.getHost(),u.getPort());

DataOutputStream dos=new DataOutputStream(s.getOutputStream());

dos.writeBytes(strOutput);

dos.close();
}
catch(IOException e)
{
// System.err.println(e);
e.printStackTrace();
}
}