A rude but possible approach is adding these object to the AppUi:
Code:
AppUi.h
public:
RSocketServ iSocketServ;
RConnestion iConnection;
AppUi::ConstructL
{
...
User::LeaveIfError(iSocketServ.Connect());
User::LeaveIfError(iConnection.Open(iSocketServ));
User::LeaveIfError(iConnection.Start());
...
}
AppUi::~AppUi
{
...
iConnection.Close();
iSocketServ.Close();
}
Then you can access these members anywhere:
Code:
// somewhere in the middle of something
iSocket.Open(
static_cast<CMyAppUi*>(CCoeEnv::Static()->AppUi())->iSocketServ,
KAfInet, KSockStream, KProtocolInetTcp,
static_cast<CMyAppUi*>(CCoeEnv::Static()->AppUi())->iConnection);
Of course it is possible to provide getter methods, put the whole thing in a separate singleton object, or even via simply using global variables.