Hi,
I'm implementing a UDP server/client using Active objects. The server listen at a port and send a ACK message back to the client.
The server code is something like this:
void CUdpServer::ConstructL(TInt aPort)
{
// CActiveScheduler::Add(this);
iMessage = CMessage::NewL();
iState = EIdle;
iAppUi->PrintMsg(_L("server constructed"));
applicationPort = aPort;
}
void
CUdpServer::DoReceive()
{
TBool ret = EFalse;
iSock.RecvFrom(iBuffer, iFrom, 0, iStatus);
applicationPort = iFrom.Port();
iAppUi->PrintMsg(_L("server receives data"));
TBuf<120> temp;
temp.Zero();
temp.Copy(iBuffer);
ret = iMessage->ParseMessage(temp, CMessage::ERegister);
if(ret)
{
iAppUi->PrintMsg(_L("server receives registration data"));
iState = EReceiving;
}
iState = EReceiving;
SetActive();
}
//================================================
void CUdpServer::DoSendConfirm()
{
const TUint32 KInetAddr2 = INET_ADDR(127,0,0,1);
TInetAddr addr(KInetAddr2, applicationPort );
iMessage->GenerateMessage(CMessage::EConfirm);
iBuffer.Zero();
iBuffer.Copy(iMessage->GetMessage());
iSock.SendTo(iBuffer, addr, 0, iStatus);
iState = EIdle;
SetActive();
}
...
void CUdpServer::RunL()
{
if(iStatus.Int() == KErrNone)
{
if(iState == EReceiving)
DoSendConfirm();
else
DoReceive();
}
}
...
void CUdpServer::Start()
{
User::LeaveIfError( iServ.Connect() );
User::LeaveIfError( iSock.Open(iServ, KAfInet, KSockDatagram, KProtocolInetUdp) );
iSock.SetLocalPort(1000);
iState = EIdle;
DoReceive();
}
The server starts by running Start() function. When the first message arrives, it could read in and process, however, then the DoSendConfirm is never invoked.
If the client sends another request, DoSendConfirm then runs the first time. It looks like the pending request from the first message now is running.
Please help.



