我正在尝试使用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);
}