Obviously you need an active object for that.
Then code like
Code:
User::LeaveIfError(iConnection.Start());
User::LeaveIfError(iSocket.Open(iSocketServer,KAfXy,KSockStream,KInetProtocolTcp,iConnection));
iSocket.Connect(iStatus,iAddress);
iState=EConnecting;
SetActive();
will become
Code:
iConnection.Start(iStatus);
iState=EStarting;
SetActive();
plus
Code:
RunL()
{
if(iStatus==KErrNone)
{
switch(iState)
{
case EStarting:
User::LeaveIfError(iSocket.Open(iSocketServer,KAfXy,KSockStream,KInetProtocolTcp,iConnection));
iSocket.Connect(iStatus,iAddress);
iState=EConnecting;
SetActive();
break;
hopefully you see the pattern.