请教一个关于Socket连接的问题
哪位大哥介绍一下怎么创建一个Socket连接?
还有创建时怎么选择接入点?可以不让弹出接入点选择框,而是由程序定义一个默认的接入点。
最好能贴些代码出来看看!多谢了!!!
[解决办法]
接入点设置:
void CMPThemeEngine::SetupConnectionL()
{
if( iConnectionSetupDone )
return;
iConnectionSetupDone = ETrue;
User::LeaveIfError(iSocketServ.Connect());
User::LeaveIfError(iConnection.Open(iSocketServ));
CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDB);
CCommsDbConnectionPrefTableView* commDBView =
commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown);
User::LeaveIfError(commDBView->GotoFirstRecord());
CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
commDBView->ReadConnectionPreferenceL(pref);
TUint32 iapID = pref.iBearer.iIapId;
CleanupStack::PopAndDestroy(commDBView);
CleanupStack::PopAndDestroy(commDB);
// Now we have the iap Id. Use it to connect for the connection.
// Create a connection preference variable.
TCommDbConnPref connectPref;
connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
connectPref.SetDirection(ECommDbConnectionDirectionUnknown);
connectPref.SetBearerSet(ECommDbBearerGPRS);
//Sets the CommDb ID of the IAP to use for this connection
connectPref.SetIapId(iapID);
User::LeaveIfError(iConnection.Start(connectPref));
RStringPool strPool = iSession.StringPool();
RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
//to use our socket server and connection
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
RHTTPSession::GetTable() ),
THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) );
}