I sometimes get a - 2147483647 as the status when using a Recv or RecvOneOrMore function.
This error sometimes occurs on the last packet not allowing a KErrEof to be returned. This seems to be the main issue as I am having difficulty determining when the data transfer is finished.
Sometimes the error is returned in the middle of receiving data, the xfer length is still set to 0, but the data buffer actually contains valid data.
Sometimes when the error code occurs, xfer length is set correctly and tere is valid data.
I've seen this too. I can't say why it happened - I was having other troubles with my active object and when they got fixed the problem just went away. I think if you convert that number to hex it looks more like a 'proper' error code you can search one of the header files (e32std?) for. I seem to recall it's 0x80000001.
whenever I got the -2147483647 I would use User::WaitForRequest(iRecvStatus); to pause the receive code. This seems to have solved my problems, I believe now that it indicates that I was accessing the received data before it was finished. Any other status no WaitForRequest was needed.
Yes, I am using an active object - here is a stripped version of my working code.
This code emulates a HTTP POST to a web server and gets the response.
(Just took out unneeded code, did not try to recompile - so might need a little work)
// Read from one file URLEncode and put in another file
void Xmit::Encode()
{
TInt err,len,temp;
RFile exfile,enfile;
User::LeaveIfError(exfile.Open(fsSession,KEFileName,EFileRead|EFileStreamText));
err=exfile.Size(len);
RFileReadStream instream(exfile);
User::LeaveIfError(enfile.Replace(fsSession,KEncFileName,EFileWrite|EFileStreamText));
RFileWriteStream outstream(enfile);
for (TInt i=0; i < len; i++) {
temp = instream.ReadInt8L();
// Read from server storing onto linked list, when done write to file
// This function is called repeatedly by RunL
void Xmit::Recv()
{
TSglQueIter<myElement> iIter(linkList);
TRequestStatus liRecvStatus(0);
myElement *tel = new myElement();
linkList.AddLast(*tel);
// use file to feed outgoing tcp conntection
// get length file size + account & password length + constant length
exfile.Size(len);
len += settings.iAccountName.Length();
len += settings.iPassword.Length();
len += 19; // add length of hardcoded strings
// must use HTTP 1.0 unless you want to do a lot of coding
outLine.Copy(_L8("POST /mobile-rescue/syncUp.do HTTP/1.0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: "));
outLine.AppendNum(len);
outLine.Append(_L8("\r\n\r\n"));
sock.Write(outLine,iTranStatus);
User::WaitForRequest(iTranStatus);
// output account and password so they get URL Encoded
class myElement
{
public:
TSglQueLink iLink;
TBuf8<250> data;
};
class Xmit : public CActive
{
enum TState {ENotConnected, ENameResolved,
ETransmitting, EReceiving,
EShuttingDownConnection};
public:
Xmit(CAppView* aAppView);
~Xmit();
/*!
@enum TErrorType
@discussion Error types encountered when reading/writing to a sockets
@value EDisconnected A disconnected error has been encountered
@value ETimeOutOnWrite A write operation has failed to complete within a predetermined period
@value EGeneralReadError A general error has been encountered during a read
@value EGeneralWriteError A general error has been encountered during a write
*/
enum TErrorType
{
EDisconnected,
ETimeOutOnWrite,
EGeneralReadError,
EGeneralWriteError
};
/*!
@function ResponseReceived
@discussion Data has been received on the socket and read into a buffer
@param aBuffer the data buffer
*/
void ResponseReceived(const TDesC8& aBuffer);
// virtual void ResponseReceived(const TDesC& aBuffer) = 0;
and you might find it runs better. I used my own status variable and had similar errors, but when I changed to iStatus it appeared to be much more resilient. I got the clue from the Symbian paper on active objects. I can't say for sure that this is important, but it might be worth a try, also perhaps on the transmit functions too (I don't do any transmitting).
I'm a new one to symbian. I gone through your code for HTTP Post. Now i wanna i small clarification. Now i have one asp page running on my webserver on ip like http://192.168.2.194/gettext.asp. it will take one parameter name called some "x" and returns some value "y".
Now could you please tell me howto use the class givenwith sample steps to carryout the task. please help.
Sridhar, settings seems to be a struct, but there are other minor things missing, to integrate it into my (or your) application. Anyway, oledocmeth did a great job to publish his code, because every second post on this forum (incuding one of myself) was asking for HTTP POST example code.
As u said settings is Structure. I tried the example but i'm getting E32USER-CBase panic 71. Could you please give me any working code if you have to connect to webserver. Mr. oledocmeth man written code with somethjing to read from file and write to some file and encoding .... I'm unable to get what he is doing as i have little knowledge in c++. Plz help me in solving the problem. I just want to connect an asp page on my server and send some request data to it and recieve the data fom the ASp page and show the result as an alert.
would you mind sending me your working code or posting a bit more of your working code here so that we can have a better understanding of it? like how to use this class to post a file or data to a URL? my email addr is pksy158@hotmail.com thank you.