Read-only archive of the All About Symbian forum (2001–2013) · About this archive

TCP socket listener using active objects...

1 replies · 5,159 views · Started 09 September 2003

hi all,

I am trying to implement TCP listener using active objects...

From what i'v read through and understood ...active objects work as follows.

1. the boolean value IsActive() is set to true and on calling the SetActive() method which i call after the Accept() call.

2. As soon as the client connects to my emulator or phone (nokia 3650) the IsActive() is set to false and the RunL() method is called...

3. The RecvOneOrMore(iMyBuffer, 0, iStatus, iMyDummyLength) is called inside the RunL() where i plan to handle data reading..and writing into stream...

but donno for some reason...the RunL() method doesn't get called probably cause the IsActive() remains true cause the client
is not able to connect...but the RunL() gets called on the action of some click event...!!

the foll. is the code am using...do please correct me...

Quote :

void CSocketsEngine::ListenL() // <a name="ConnectL32">
{

{


User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp));

#define KTestPort 8030
TInetAddr anyAddrOnPort(KInetAddrAny, KTestPort);
iConsole.ErrorNotify(_L("Going to bind to port 8030"😉, iEngineStatus);
TInt bindStat = iSocket.Bind(anyAddrOnPort);

if (bindStat == KErrNone) {
TBuf8<10> stat;
_LIT8(kStat,"%d"😉;
stat.Format(kStat,bindStat);
iConsole.ErrorNotify(_L("Bind Success"😉, iEngineStatus);
}

//Listening for socket connections
TUint queSize = 5;
TUint popConn;
iConsole.ErrorNotify(_L("Before Listen Call"😉, iEngineStatus);
popConn = iSocket.Listen(queSize);
TBuf8<5> statListen;

_LIT8(kstatListen,"%d"😉;
statListen.Format(kstatListen,popConn);
iConsole.ErrorNotify(_L("Listen QueSize Set"😉, iEngineStatus);

//Accept every connection as and when it comes in from the
//listen call..

RSocket blankRSock;
TInt blsock = 0;
blsock = User::LeaveIfError(blankRSock.Open(iSocketServ));

TRequestStatus reqStat(blsock);
iSocket.Accept(blankRSock,reqStat);
iConsole.ErrorNotify(_L("Awaiting client conn..."😉, iEngineStatus);

ChangeStatus(EReceive);
SetActive();

}
}

UnQuote :

thanx,
adios,
LearningCurve

Whenever u make a request to a service provider, u need to pass in
the inherited iStatus variable before calling the SetActive() function.

Hence the following code,

TRequestStatus reqStat(blsock);
iSocket.Accept(blankRSock,reqStat);

should be changed to

TRequestStatus reqStat(blsock);
iSocket.Accept(blankRSock,iStatus);