×

Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 45
  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    24

    wierd error code - 2147483647 on TCP receive

    Can any one explain what this error code means?

    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.

    Thanks,

    Rich Pearson

  2. #2
    Regular Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, Great Britain
    Posts
    98
    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.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    24

    This worked for me -

    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.

  4. #4
    Regular Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, Great Britain
    Posts
    98
    Are you in an active object, or 'normal' code?

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    24

    Code for HTTP POST

    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)

    Xmit.cpp:
    #include <e32base.h>
    #include <e32std.h>
    #include "Xmit.h"

    _LIT(KDefaultServerName, "www.yahoo.com");
    _LIT(KDefaultAccountName, "");
    _LIT(KDefaultPassword, "");

    Xmit::Xmit(CAppView* aAppView)
    : CActive(EPriorityStandard),
    reslen(0)
    {
    settings.iPort = 8080;
    settings.iServerName = KDefaultServerName;
    settings.iAccountName = KDefaultAccountName;
    settings.iPassword = KDefaultPassword;

    iAppView = aAppView;
    iConnectState = ENotConnected;

    User::LeaveIfError(fsSession.Connect()); // connect session
    fsSession.MkDirAll(KDirName);
    fsSession.MkDirAll(KSettingsDir);

    }

    Xmit* Xmit::NewLC(CAppView* aAppView)
    {
    Xmit* self = new (ELeave) Xmit(aAppView);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

    Xmit* Xmit::NewL(CAppView* aAppView)
    {
    Xmit* self = NewLC(aAppView);
    CleanupStack::Pop();
    return self;
    }

    void Xmit::ConstructL()
    {
    CActiveScheduler::Add(this);
    }

    Xmit::~Xmit()
    {

    }

    void Xmit:oCancel()
    {
    if (cancelfirst == 1) {
    // CActive:eque();
    sock.CancelRecv();
    sock.CancelAll();
    sock.Close();
    resolver.Close();
    socksvr.Close();
    cancelfirst = 0;
    }
    }

    void Xmit::IssueRequest()
    {
    TInt err;

    Encode();

    firsttime = 0;
    exitfirst = 0;
    msglen = 0;
    // Announce our intentions
    iAppView->SetStatus(_L("Finding Server..."),_L(""));

    // Connect to the Socket server
    err = socksvr.Connect();
    User::LeaveIfError(err);

    // Now resolve the name given in the URL
    err = resolver.Open(socksvr, KAfInet, KProtocolInetTcp);
    User::LeaveIfError(err);

    resolver.GetByName(settings.iServerName, iHostEnt, iTranStatus);

    iConnectState = ENameResolved;
    cancelfirst = 1;

    SetActive();
    }

    void Xmit::RunL()
    {
    TInt err;

    switch (iConnectState) {
    case ENameResolved:
    if (iTranStatus == KErrNone) {
    // Announce our intentions
    iAppView->SetStatus(_L("Connecting..."),_L(""));

    // open the socket
    err = sock.Open(socksvr, KAfInet, KSockStream, KProtocolInetTcp);
    User::LeaveIfError(err);

    // Set up address information
    iAddress = iHostEnt().iAddr;
    iAddress.SetPort(settings.iPort);

    // Initiate socket connection
    sock.Connect(iAddress, iTranStatus);

    // start the connection process
    iConnectState = ETransmitting;

    SetActive();
    } else {
    // handle an error in name resolution
    }
    break;

    case ETransmitting:
    // Announce our intentions
    iAppView->SetStatus(_L("Sending"),_L(""));
    Send();
    iConnectState = EReceiving;
    SetActive();
    break;

    case EReceiving:
    // Announce our intentions
    iAppView->SetStatus(_L("Receiving"),_L(""));
    Recv();
    break;
    }

    if ((iConnectState == EShuttingDownConnection) && (exitfirst == 0)) {
    exitfirst = 1;
    iAppView->SetStatus(_L("Closing Connection"),_L(""));
    DoCancel();
    imfile.Close();
    iAppView->SetStatus(_L("Finished."),_L(""));
    // delete this;
    }
    }

    // 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();

    if (((temp > 47) && (temp < 58)) || ((temp > 64) && (temp < 91)) || ((temp > 96) && (temp < 123))) {
    outstream.WriteInt8L(temp);
    } else {
    TBuf8<4> str;
    str.Append(_L8("%"));
    str.AppendNumFixedWidth((TUint)temp, EHex,2);
    outstream.WriteL(str);
    }
    }

    outstream.CommitL();
    outstream.Close();
    enfile.Close();
    instream.Close();
    exfile.Close();
    }

    // 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);

    if (firsttime == 0) {
    // overwrite previous recv
    User::LeaveIfError(imfile.Replace(fsSession,KIFileName,EFileWrite|EFileStream|EFileShareAny));
    firsttime = 1;
    }

    if (liRecvStatus != KErrEof) {
    if (liRecvStatus == -2147483647) {
    User::WaitForRequest(liRecvStatus);
    }
    msglen += reslen();
    sock.RecvOneOrMore(tel->data, 0, liRecvStatus, reslen);

    if ((liRecvStatus.Int() < 0) && (liRecvStatus.Int() != -2147483647)) {
    switch (liRecvStatus.Int()) {
    case -36:
    iAppView->SetStatus(_L("Error: Connection Failed"),_L("GPRS Disconnected"));
    break;

    default:
    iAppView->SetStatus(_L("Error: Connection Failed"),_L(""));
    }
    iConnectState = EShuttingDownConnection;
    }
    }

    if (liRecvStatus == KErrEof) {
    iConnectState = EShuttingDownConnection;
    iIter.SetToFirst();
    while (iIter != NULL) {
    myElement *ttel = (myElement *)iIter;
    imfile.Write(ttel->data);
    imfile.Flush();
    iIter++;
    }
    }
    // delete tel;
    SetActive();
    }

    // Send the contents of a file to the server
    // as a POST request
    void Xmit::Send()
    {
    RFile exfile;
    TInt err,len;

    User::LeaveIfError(exfile.Open(fsSession,KEncFileName,EFileRead|EFileStreamText));

    // 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

    outLine.Copy(_L8("acct="));
    outLine.Append(settings.iAccountName);
    outLine.Append(_L8("&passwd="));
    outLine.Append(settings.iPassword);
    outLine.Append(_L8("&data="));
    sock.Write(outLine,iTranStatus);
    User::WaitForRequest(iTranStatus);

    while(1) {
    outLine.Zero();
    err = exfile.Read(outLine,512);
    if (outLine.Length() == 0) break;
    sock.Write(outLine, iTranStatus);
    User::WaitForRequest(iTranStatus);
    }

    outLine.Copy(_L8("\r\n"));
    sock.Write(outLine,iTranStatus);
    exfile.Close();
    }

    // These functions are used by the GUI
    void Xmit::SetServerName(const TDesC& aName)
    {
    settings.iServerName.Copy(aName);
    }

    const TDesC& Xmit::ServerName() const
    {
    return settings.iServerName;
    }

    void Xmit::SetPort(TInt aPort)
    {
    settings.iPort = aPort;
    }

    TInt Xmit::Port() const
    {
    return settings.iPort;
    }

    void Xmit::SetAccountName(const TDesC& aName)
    {
    settings.iAccountName.Copy(aName);
    }

    const TDesC& Xmit::AccountName() const
    {
    return settings.iAccountName;
    }

    void Xmit::SetPassword(const TDesC& aName)
    {
    settings.iPassword.Copy(aName);
    }

    const TDesC& Xmit::Password() const
    {
    return settings.iPassword;
    }

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    24

    Continuing HTTP POST code

    Xmit.h:

    #ifndef __XMIT_H__
    #define __XMIT_H__

    #include <es_sock.h>
    #include <in_sock.h>
    #include <e32std.h>

    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;

    public:

    static Xmit* NewLC(CAppView* aAppView);
    static Xmit* NewL(CAppView* aAppView);

    public:
    void ConstructL();
    void DoCancel();
    void RunL();
    void IssueRequest();
    void Send();
    void Recv();

    /*!
    @function SetServerName

    @discussion Set name of server to connect to
    @param aName new server name
    */
    void SetServerName(const TDesC& aName);

    /*!
    @function ServerName

    @discussion Get server name
    @result name of server
    */
    const TDesC& ServerName() const;

    /*!
    @function SetPort

    @discussion Set port number to connect to
    @param aPort new port number
    */
    void SetPort(TInt aPort);

    /*!
    @function Port

    @discussion Get port number
    @result port number
    */
    TInt Port() const;


    /*!
    @function SetAccountName

    @discussion Set name of account
    @param aName new account name
    */
    void SetAccountName(const TDesC& aName);

    /*!
    @function AccountName

    @discussion Get account name
    @result name of account
    */
    const TDesC& AccountName() const;

    /*!
    @function SetPassword

    @discussion Set password of account
    @param aName new password
    */
    void SetPassword(const TDesC& aName);

    /*!
    @function Password

    @discussion Get password
    @result password
    */
    const TDesC& Password() const;

    private:
    CAppView* iAppView;
    RSocketServ socksvr;
    RSocket sock;
    RHostResolver resolver;
    TState iConnectState;
    TNameEntry iHostEnt;
    TRequestStatus iTranStatus;
    TRequestStatus iRecvStatus;
    TSockXfrLength reslen;

    /*! @var The address to be used in the connection */
    TInetAddr iAddress;

    RFile imfile;
    RFs fsSession;

    TBuf8<512> iLine;
    TBuf8<1024> outLine;
    TSglQue<myElement> linkList;
    TInt firsttime,exitfirst,cancelfirst;
    TInt offset,len,msglen;
    };

    #endif // __XMIT_H__

  7. #7
    Regular Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, Great Britain
    Posts
    98
    Replace

    sock.RecvOneOrMore(tel->data, 0, liRecvStatus, reslen);

    with

    sock.RecvOneOrMore(tel->data, 0, iStatus, reslen);

    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).

  8. #8
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    77

    code for http post

    Hi oledocmeth,

    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.


    thanks in advance.

    Sridhar

  9. #9
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    99

    compile error

    hi oledocmeth,

    thanz for your code! =) i've tried your code and when i compile, settings is giving error. may i know what class or datatype is settings?

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    7
    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.

    Roberto

  11. #11
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    77
    hi rsaccon

    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.

    plz help me.


    thanks in advance.

    Sridhar Reddy .R

  12. #12
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    99

    struct?

    hi! i've tried putting it in a structure but it compiles error stating that:

    1) warning C4510: 'Settings' : default constructor could not be generated
    2) error C2039: 'Copy' : is not a member of 'TDesC16'

    Here is my declaration of the structure:

    struct Settings
    {
    TInt iPort;
    TDesC& iServerName;
    TDesC& iAccountName;
    TDesC& iPassword;
    };

    May i know where have i went wrong?

  13. #13
    Registered User
    Join Date
    May 2003
    Posts
    24
    use TBuf8 instead

  14. #14
    Registered User
    Join Date
    Jul 2003
    Posts
    10

    See example HTTP Server

    This example written by a developer at symbian is an example HTTP server.

    see http://www.symbian.com/developer/techlib/staffapps.html

    The above example misunderstands active object concepts.

    -2147483647 = KRequestPending... see e32std.h

    see SDK documentation

    http://www.symbian.com/developer/tec...verview%2emain

    See white papers on core Symbian OS techniques

    http://www.symbian.com/developer/tec...ngstarted.html

  15. #15
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    99
    hi Sridhar and Roberto,

    so did u all managed to get the http post working? can send me a copy of your code if u can get it working?


    hi oledocmeth,

    TBuf8 still doesn't solve the problem. it says that

    'Copy' : is not a member of 'TBuf8' and
    error C2440: 'return' : cannot convert from 'class TBuf8' to 'const class TDesC16' in

    const TDesC& Xmit::ServerName() const
    {
    return settings.iServerName;
    }

    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.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •