tags:

views:

281

answers:

2
void CSocket::WriteSocket()
{
 TBuf8<2> KData (_L8("60"));
//RBuf8 KData;
 RBuf8 aQuery;
 aQuery.CleanupClosePushL(); 
 aQuery.CreateL(100);
// <?xml version="1.0"?><AM><P/><A><CE/></A></AM>
 _LIT8(KData1,"61");
 //_LIT8(KData2,"20");
 _LIT8(KData3,"A");
 _LIT8(KData4,"<?xml version=\"1.0\"?><AM><P/><A><CE/></A></AM>");
 TBuf8<100> buff,buff1;
 buff.Copy(_L("<?xml version=\"1.0\"?><AM><P/><A><CE/></A></AM>"));
 TInt len=buff.Length();
 buff1.AppendNum(len);
 aQuery.Append(KData1);
 aQuery.Append(buff1);
// aQuery.Append(KData2);
 aQuery.Append(KData3);
 aQuery.Append(buff); 
 //iSocket.Send(KData,KExpeditedDataOpt,iStatus);
 iSocket.Write((TDesC8)aQuery,iStatus);
 User::WaitForRequest(iStatus); 
}

I am using this code on Symbian for communication with server which is in Java.

But the issue is: the data is not reaching the server. It is showing device has succesfully connected. What i am doing wrong in this code? Is TDes8 compatible with plain text in Java?

+1  A: 

TDes8 is just bytes, which is fine if the Java end is trying to read ASCII, not so fine if the Java end is expecting 16bit unicode (which is what Java's char is). But if you're reading the socket at the other end, then even if it wasn't compatible you'd still see some data, just not what you were expecting. And the protocol by which you're communicating with the server should specify the charset, regardless of what language the server is implemented in.

Otherwise:

  • Does it work on the emulator?
  • Have you checked iStatus for errors? Normally if a socket connects you can write to it, but you never know.
  • Is the server reporting that the socket is connected? It's possible you've connected to the wrong host or the wrong port.
  • If the server did read some data, but then failed for some reason, would you know? I guess I'm asking whether you're debugging the other end too. If not then it's possible your data isn't in the right format and is being ignored at the other end. I think you're sending 6146A<?xml version="1.0"?><AM><P/><A><CE/></A></AM>. Some tracing and/or packet sniffing will tell you whether that's true.
  • A variable starting with "a" is usually a parameter: is this your real code? If not, then the thing about the malformed data applies, and your caller might be giving you the wrong thing.
  • You might want to PopAndDestroy aQuery before return, although that doesn't affect this issue.
  • Your function should be called WriteSocketL, since it can leave.
Steve Jessop
hi,thanks for reply i am connecting to networkbut it shows null at server side
+1  A: 

cross-posting reply from duplicated question:

Your mobile network operator could be blocking any non-HTTP traffic.

Your server could need to receive more data before returning it all.

I'm also particularly concerned about your use of java character/string considering I would expect a low-level java socket on the server to put incoming network data in a byte[], not a String. If your server is using something like a call to a readLine() method, you may need to add a carriage return character in the data your client sends.

QuickRecipesOnSymbianOS