我正在尝试使用 Symbian 配置 RFCOMM 服务器。
查看我的代码,似乎我没有遗漏任何内容,但其他设备只是看不到我的服务。
我使用笔记本列出了手机上所有可用的蓝牙服务,但该服务不存在。
有人能帮助我吗?
这是代码:
void BtServer::StartServicoL()
{
TProtocolDesc pdesc;
User::LeaveIfError(iSocketServer.FindProtocol(NOMERFCOMM(), pdesc));
iState = EFindingAvailablePort;
User::LeaveIfError(iListeningSocket.Open(iSocketServer, NOMERFCOMM));
User::LeaveIfError(iListeningSocket.GetOpt(KRFCOMMGetAvailableServerChannel, KSolBtRFCOMM, iPort));
iState = EBinding;
iBtSocketAddr.SetPort(iPort);
User::LeaveIfError(iListeningSocket.Bind(iBtSocketAddr));
User::LeaveIfError(iListeningSocket.Listen(1));
iServiceAdvertiser->StartL(iPort);
iBtSocketAddr.SetSecurity(iBtSecurity);
iAcceptingSocket.Close();
User::LeaveIfError(iAcceptingSocket.Open(iSocketServer));
iListeningSocket.Accept(iAcceptingSocket, iStatus);
SetActive();
}
void CBluetoothServiceAdvertiser::StartL(const TInt aPort)
{
iPort = aPort;
iState = EConnecting;
User::LeaveIfError(iSdpServ.Connect());
User::LeaveIfError(iSdpDatabase.Open(iSdpServ));
TUUID serviceUUID(UUID_SERVICE);
iSdpDatabase.CreateServiceRecordL(serviceUUID, iRecordHandle);
CSdpAttrValueDES* protocolDescriptorList = CSdpAttrValueDES::NewDESL(NULL);
CleanupStack::PushL(protocolDescriptorList);
TBuf8<TAM_MAX_NRO_PORTA> port;
port.Append((TChar)iPort);
protocolDescriptorList
->StartListL()
->BuildDESL()
->StartListL()
->BuildUUIDL(KRFCOMM)
->BuildUintL(port)
->EndListL()
->EndListL();
iSdpDatabase.UpdateAttributeL(iRecordHandle, KSdpAttrIdProtocolDescriptorList, *protocolDescriptorList);
CleanupStack::PopAndDestroy(protocolDescriptorList);
iSdpDatabase.UpdateAttributeL(iRecordHandle, KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName, NOME_SERV);
iSdpDatabase.UpdateAttributeL(iRecordHandle, KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceDescription, DESC_SERV);
CSdpAttrValue* attrVal = NULL;
TBuf8<TAM_MAX_SERV_DISP> avail;
avail.FillZ(1);
avail[0]=0xff;
attrVal = CSdpAttrValueUint::NewUintL(avail);
CleanupStack::PushL(attrVal);
iSdpDatabase.UpdateAttributeL(iRecordHandle, KSdpAttrIdServiceAvailability, *attrVal);
CleanupStack::PopAndDestroy(attrVal);
}