110,566
社区成员
发帖
与我相关
我的任务
分享
private static byte[] GenerateSDPRecord(Guid serviceGuid, int channel)
{
// build the most basic SDP record specifying the service GUID and channel
byte[] sdpRecord = new byte[] { 0x35, 0x00, 0x09, 0x00, 0x01, 0x35, 0x11, 0x1c,
/* guid goes here */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* L2CAP + RFCOMM */ 0x09, 0x00, 0x04, 0x35, 0x0c, 0x35, 0x03, 0x19,
0x01, 0x00, 0x35, 0x05, 0x19, 0x00, 0x03, 0x08,
/* channel number here */ 0x00 };
// set sdp record length
sdpRecord[1] = Convert.ToByte(sdpRecord.Length - 2);
// copy in the service guid in network byte order
byte[] guidArray = serviceGuid.ToByteArray();
sdpRecord[8] = guidArray[3];
sdpRecord[9] = guidArray[2];
sdpRecord[10] = guidArray[1];
sdpRecord[11] = guidArray[0];
sdpRecord[12] = guidArray[5];
sdpRecord[13] = guidArray[4];
sdpRecord[14] = guidArray[7];
sdpRecord[15] = guidArray[6];
Array.Copy(guidArray, 8, sdpRecord, 16, 8);
// last byte is the RFCOMM channel
sdpRecord[sdpRecord.Length - 1] = Convert.ToByte(channel);
return sdpRecord;
}