hi all,
i'm developing a TCP client application and found there are two problem with RSocket.
- while connecting to a non-existing ip address with RSocket::Connect(iAddr, iStatus), RSocket will block in Connect() for 20~30 seconds then next step over SetActive(). This problem won't happened on target device.(I realize this problem had been asked on the forum, but i did't see the problem has been cleared)
- there are two ip address, one(say, A) can be reached and the other(say, B) can't. if RSocket first connect to B then connect to A, it will result in:
RSocket connect to B --> enter RunL with error code -33(time out) --> RSocket connect to A --> enter RunL with error code -33
that's wield! i'm sure that host A can be reached.
the problem can be solved if i do RSocket::Close() and then RSocket::Open() before connecting to A. that is,
RSocket connect to B --> enter RunL with error code -33(time out) --> do RSocket::Clsoe() --> do RSocket::Open() --> RSocket connect to A --> enter RunL with KErrNone
however, i dont think that's a good metholody...
Socket should be reusable, even if there are something wrong(eg, connection error) with it, isn't it ?
this is my code snippet
cpp
Code:
TEST* TEST::NewL()
{
TEST* self = new(ELeave) TEST;
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
void TEST::ConstructL()
{
iSocketServ.Connect();
iConn.Open( iSocketServ );
iConn.Start();
iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp,iConn);
}
TEST::TEST() : CActive(0)
{
CActiveScheduler::Add(this);
}
TEST::~TEST()
{
Cancel();
}
void TEST::RunL()
{
User::LeaveIfError(iStatus.Int());
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(_L("connected"));
}
void TEST::DoCancel()
{
}
TInt TEST::RunError(TInt aError)
{
TBuf<64> msg;
msg.Format(_L("err: %d"), aError);
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(msg);
return 0;
}
void TEST::ConnectL(TInetAddr& aAddr)
{
iAddr = aAddr;
iSocket.Connect(iAddr, iStatus);
SetActive();
}
and header
Code:
class TEST :public CActive
{
public:
static TEST* NewL();
~TEST();
private:
void ConstructL();
TEST();
protected:
void RunL();
void DoCancel();
TInt RunError(TInt aError);
public:
void ConnectL(TInetAddr& aAddr);
private:
RSocket iSocket;
RSocketServ iSocketServ;
RConnection iConn;
TInetAddr iAddr;
};
thanks in advance,
any comment will be appreciated