Hi group here is my code of a TCP/IP client.
It appears to be right, but if this code runs in the device every
minute in a timer function, it crash the phone.
i don't know what is wrong. But I think that the function connect of the RSocket class is the problem. If someonw want to test it here is the code.

**************************MySockets.cpp**************************
#include "MySockets.h"
#include "TimeOutTimer.h"

static const TInt KTimeOut = 30000000; // 30 seconds time-out

CMySockets* CMySockets::NewL()
{
CMySockets* self = NewLC();
CleanupStack::Pop(self);
return self;
}


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


CMySockets::CMySockets()
: CActive(CActive::EPriorityStandard)
{
CActiveScheduler::Add(this);
}


CMySockets::~CMySockets()
{
Cancel();

delete iTimer;
delete iDb;
}


void CMySockets::ConstructL()
{

User::LeaveIfError(iSocketServ.Connect());

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

iTimer = CTimeOutTimer::NewL(EPriorityHigh, *this);
iDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
}


void CMySockets:oCancel()
{
}


void CMySockets::RunL()
{
iTimer->Cancel();
switch(iMySocketsStatus)
{
case EConnected:
Disconnect();
break;
}

}

void CMySockets::TimerExpired()
{
Cancel();
iSocket.CancelConnect();
Disconnect ();
}

void CMySockets::State(TMySocketsStatus aEstado)
{
iMySocketsStatus = aEstado;
}

void CMySockets::Connect(TUint32 aAddr, TInt aPort)
{
if (IsActive())
{
User::Leave(KErrInUse);
}
iDb->SetGlobalSettingL(TPtrC(ASK_USER_BEFORE_DIAL),(TInt) EFalse);

iAddress.SetPort(aPort);
iAddress.SetAddress(aAddr);

iSocket.Connect(iAddress, iStatus);

State(EConnecting);

SetActive();

iTimer->After(KTimeOut);

}

void CMySockets:isconnect()
{
iSocket.Close();
iSocketServ.Close();
iDb->SetGlobalSettingL(TPtrC(ASK_USER_BEFORE_DIAL),(TInt)ETrue);
User::Exit(0);

}


*****************************MySockets.h****************************
#ifndef __MYSOCKETS_H__
#define __MYSOCKETS_H__

#include <e32base.h>


//MIS INCLUDES
#include <in_sock.h>
#include <agentclient.h>
#include <commdb.h>
#include "TimeOut.h"

class CTimeOutTimer;

class CMySockets : public CActive, public MTimeOut
{
private:
//Estructuras
enum TMySocketsStatus
{
//ENoConcectado
EConectando,
//EConectado
};

public:
/*!
@funcion ConectarL

@discussion Conecta a la direccion especificada en el parametro aAddr
*/
void ConnectL(TUint32 aAddr, TInt aPort);

/*!
@function NewL

@discussion Create a CMySockets object
@result a pointer to the created instance of CMySockets
*/
static CMySockets* NewL();

/*!
@function NewLC

@discussion Create a CMySockets object
@result a pointer to the created instance of CMySockets
*/
static CMySockets* NewLC();

/*!
@function ~CMySockets

@discussion Destroy the object and release all memory objects
*/
~CMySockets();

protected: // from CActive
void TimerExpired();

/*!
@function DoCancel

@discussion Cancel any outstanding requests
*/
void DoCancel();

/*!
@function RunL

@discussion Respond to an event
*/
void RunL();

private:

/*!
@function CMySockets

@discussion Constructs this object
*/
CMySockets();

/*!
@function ConstructL

@discussion Performs second phase construction of this object
*/
void ConstructL();
/*!
@funcion CambiarEstado

*/
void State(TMySocketsStatus aEstado);


private:
void Disconnect();

// Member variables
TMySocketsStatus iMySocketsStatus;
RSocket iSocket; // the actual socket
RSocketServ iSocketServ; // the socket server
TInetAddr iAddress;
TInt iPort; // port number to connect to
TBuf<50> iServerName; // server name to connect to
CCommsDatabase* iDb;
CTimeOutTimer* iTimer; // timer active object
};

#endif // __MYSOCKETS_H__



**************************TimerOutTimer.h***************************
#ifndef __TIMEOUTTIMER_H__
#define __TIMEOUTTIMER_H__

class MTimeOut;

#include <e32base.h>

class CTimeOutTimer : public CTimer
{
public:

/*!
@function NewL

@discussion Create a CTimeOutTimer object
@param aPriority, prioridad que se le asigna al objeto CTimer.
@param aTimeOut, objeto de tipo MTimeOut, para realizar las notificaciones.
@result a pointer to the created instance of CTimeOutTimer
*/
static CTimeOutTimer* NewL(const TInt aPriority, MTimeOut& aTimeOut);

/*!
@function NewLC

@discussion Create a CTimeOutTimer object
@param aPriority, prioridad que se le asigna al objeto CTimer.
@param aTimeOut, objeto de tipo MTimeOut, para realizar las notificaciones.
@result a pointer to the created instance of CTimeOutTimer
*/
static CTimeOutTimer* NewLC(const TInt aPriority, MTimeOut& aTimeOut);

/*!
@function ~CTimeOutTimer

@discussion Destroy the object and release all memory objects
*/
~CTimeOutTimer();

protected: // From CTimer
/*!
@function RunL

@discussion Invoked when a timeout occurs
*/
virtual void RunL();

private:
/*!
@function CTimeOutTimer

@discussion Perform the first phase of two phase construction
@param aPriority priority to use for this timer
*/
CTimeOutTimer(const TInt aPriority, MTimeOut& aTimeOut);

/*!
@function ConstructL

@discussion Perform the second phase construction of a CTimeOutTimer
*/
void ConstructL();

private:
// Member variables
MTimeOut& iNotify;
};

#endif // __TIMEOUTTIMER_H__


****************************TimerOutTimer.cpp**********************
#include "TimeOutTimer.h"
#include "TimeOut.h"

CTimeOutTimer* CTimeOutTimer::NewL(const TInt aPriority, MTimeOut& aTimeOut)
{
CTimeOutTimer* self = NewLC(aPriority, aTimeOut);
CleanupStack::Pop(self);
return self;
}


CTimeOutTimer* CTimeOutTimer::NewLC(const TInt aPriority, MTimeOut& aTimeOut)
{
CTimeOutTimer* self = new (ELeave) CTimeOutTimer(aPriority, aTimeOut);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}


CTimeOutTimer::CTimeOutTimer(const TInt aPriority, MTimeOut& aTimeOut)
: CTimer(aPriority), iNotify(aTimeOut)
{
}


CTimeOutTimer::~CTimeOutTimer()
{
Cancel();
}


void CTimeOutTimer::ConstructL()
{
CTimer::ConstructL();
CActiveScheduler::Add(this);
}

void CTimeOutTimer::RunL()
{
iNotify.TimerExpired();
}


****************************Timeout.h********************

#ifndef __TIMEOUT_H__
#define __TIMEOUT_H__

class MTimeOut
{
public:
/*!
@function TimerExpired

*/
virtual void TimerExpired() = 0;

};

#endif // __TIMEOUT_H__


The CTimeOutTimer class and MTimeOut, implements the timer event.

in the main app you mus put this code an it will run, and now implements the timer events, that calls ConnectL() method and test ti. After a day, the device or the app will crash.
I don't know why, but it appears like a memory leak.

******************************
iMySockets = CMySockets::NewL();
TInetAddr addr;
addr.Input(KDefaultServerName);
iMySockets->ConnetcL(addr.Address(), KDefaultPortNumber);
******************************

Thx in advance