Symbian 得到接入点ID-网络编程简单示例
来源:互联网 发布:北京王府井mac专柜 编辑:程序博客网 时间:2024/05/21 22:40
在用如下代码创建连接时:
RSocketServ socketServ;
RConnection connection;
TCommDbConnPref pref;
TRequestStatus rsConn, rsTimeout;
Timer Timer;
User::LeaveIfError(socketServ.Connect());
User::LeaveIfError(connect.Open(socketServ));
pref.SetDialogPreference(ECommDbDialogPrefPrompt);
pref.SetDirection(ECommDbConnectionDirectionOutoing);
pref.SetBearerSet(ECommDbBearerUnknown);
if(Timer.CreateLocal() == KErrNone)
{
Timer::After(rsTimeout, 30 * 1000 * 1000)
connection.Start(pref, rsConn);
User::WaitForRequest(rsConn, rsTimeout);
switch(rsConn.Int())
{
case KErrNone:
case KErrInUse;
case KErrAlreadyExists:
dafault:
}
if(rsConn == KRequestPending)
{
connection.Stop();
User::WaitForRequest(rsCconn);
}
if(rsTimeout == KRequestPending)
{
Timer::Calcel();
User::WaitForRequest(rsTimeout);
}
Timer::Close();
}
connection.Close();
socketServ.Close();
会有提示选择接入点的对话框出现. 在选择了接入点之后, 可以用:
TUint32 iap(0);
_LIT(KCommdbIapSetting, "IAP//Id");
User::LeaveIfError(connection.GetIntSetting(KCommdbIapSetting, iap));
得到接入点的ID, 这里iap就是接入点的ID.
2, 获得活跃的接入点
TUint32 iap = 0;
RSocketServ socketServ;
User::LeaveIfError(socketServ.Connect());
CleanupClosePushL(socketServ);
RConnection conn;
User::LeaveIfError(conn.Open(socketServ));
CleanupClosePushL(conn);
TUint count = 0;
User::LeaveIfError(conn.EnumerateConnections(count));
TConnectionInfoBuf connectionInfo;
TUint i;
for(; count > 0; count--)
{
User::LeaveIfError(conn.GetConnectionInfo(count,connectionInfo));
iap = connectionInfo().iIapId;
}
CleanupStack::PopAndDestroy(2, &socketServ);
3, 轮询可用的接入点:
3.1
(from: http://www.ok371.cn/html/13/0/999/1.htm)
How do I get a list of Internet Access Point (IAP) names and the corresponding ID values?
Answer:
An Internet Access Point (IAP) is a table in Symbian's Communication database (CommDB) which provides an entry point for making a connection over a given bearer type e.g. GPRS, WCDMA, GSM Data Call etc. There can be several IAP records in the IAP table within CommDB each pointing to a different connection type.Note : The example code below uses Symbian OS APIs directly. Some SDKs might include UI Platform specific APIs to achieve the same thing. You can use
the Symbian APIs to allow your solution to work over different platforms - though any future changes made to CommDB API/functionality will affect your
implementation.
How do I get a list of IAP's names?
The below code snippet below showshow to get the IAP names for GPRS (and also WCDMA).
TUint32 CCommsDBAccessor::GetGPRSIAPsFromIAPTableL(CDesCArrayFlat* aList)
{
TBuf<52> iapfromtable;
TInt err = KErrNone;
// Open IAP table using the GPRS as the bearer.
- CCommsDbTableView* gprsTable = iCommsDB->OpenIAPTableViewMatchingBearerSetLC(ECommDbBearerGPRS,
ECommDbConnectionDirectionOutgoing);
User::LeaveIfError(gprsTable->GotoFirstRecord());
gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
aList->AppendL(iapfromtable);
while (err = gprsTable->GotoNextRecord(), err == KErrNone)
{
gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
aList->AppendL(iapfromtable);
}
CleanupStack::PopAndDestroy(); // gprsTable
}
How do I get the IAP ID values?
You can extend the second example above to get the IAP value. Include the line below
to read the IAP value for each record.
TUint32 id=0;
gprsTable->ReadUintL(TPtrC(COMMDB_ID), id);
The IAP value can be used in the override settings when making a connection. See FAQ 1064 for more details.
3.2
CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDb);
//commDb->ShowHiddenRecords(); //如果调用了这个函数,而程序又没有相应都权限, 那么在调用commDb->OpenTableLC(时会有异常抛出,该异常无法被抓住。
CCommsDbTableView* view = commDb->OpenTableLC(TPtrC(IAP));
for (TInt i = view->GotoFirstRecord(); i != KErrNotFound; i = view->GotoNextRecord())
{
TUint32 iapId;
TBuf<512> iapName;
view->ReadUintL(TPtrC(COMMDB_ID), iapId);
view->ReadTextL(TPtrC(COMMDB_NAME), iapName);
}
CleanupStack::PopAndDestroy(2, commDb); // view, commDb
iapTable->ReadUintL(TPtrC(COMMDB_ID), id);
iapTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
if (iapfromtable == findString)
return id;
while (err = iapTable->GotoNextRecord(), err == KErrNone)
{
iapTable->ReadUintL(TPtrC(COMMDB_ID), id);
iapTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
if (iapfromtable == findString)
return id;
}
return KErrNotFound;
}
- Symbian 得到接入点ID-网络编程简单示例
- Symbian 得到接入点ID-网络编程简单示例
- Symbian IAP 浅谈(Symbian网络接入点常用编程)
- 【symbian】开发之【网络编程--接入点选择】
- 得到接入点ID(IAP ID)
- 得到接入点ID(IAP ID)
- 【转】Symbian IAP 浅谈(Symbian网络接入点常用编程)
- 【转】Symbian IAP 浅谈(Symbian网络接入点常用编程)
- Symbian中的接入点
- symbian 接入点
- APN symbian手机上的接入点编程
- APN symbian手机上的接入点编程
- 网络编程简单示例
- 【转】Symbian中的接入点
- symbian 创建cmwap接入点
- Linux网络编程简单示例
- Linux网络编程简单示例
- Linux网络编程简单示例
- Sun Solaris 修改IP地址或者主机名
- 50种方法巧妙优化你的SQL Server数据库
- 阿捷的XML入门教程
- 12个.net 开发者值得去读的国外Blog
- DEBUG使用详解
- Symbian 得到接入点ID-网络编程简单示例
- C# 反射入门知识
- asp.net中动态修改配置文件的方法
- NeHe 课程笔记01
- Boost库在.net2008下的使用(4)
- jsp中的乱码问题和mysql的乱码问题
- 数字水印的扩频方式
- apache ,html,jsp 避免页面中的部分资源被cache
- c++中查找摸个字段!