OS:windows ce6.0
code:
#region Serialize
/// <summary>
/// Serializes endpoint information into a <see cref="SocketAddress"/> instance.
/// </summary>
/// <returns>A <see cref="SocketAddress"/> instance containing the socket address for the endpoint.</returns>
public override SocketAddress Serialize()
{
//#if WinCE
SocketAddress btsa = new SocketAddress(AddressFamily32.Bluetooth, 40);//40
//#else
// SocketAddress btsa = new SocketAddress(AddressFamily32.Bluetooth, 30);
//#endif
//copy address type
btsa[0] = 32;
//copy device id
if (m_id != null)
{
byte[ deviceidbytes = m_id.ToByteArray();
for (int idbyte = 0; idbyte < 6; idbyte++)
{
//#if WinCE
btsa[idbyte + 8] = deviceidbytes[idbyte];
//#else
// btsa[idbyte + 2] = deviceidbytes[idbyte];
//#endif
}
}
//copy service clsid
if (m_service != Guid.Empty)
{
byte[ servicebytes = m_service.ToByteArray();
for (int servicebyte = 0; servicebyte < 16; servicebyte++)
{
//#if WinCE
btsa[servicebyte + 16] = servicebytes[servicebyte];
//#else
// btsa[servicebyte + 10] = servicebytes[servicebyte];
//#endif
}
}
//copy port
byte[ portbytes = BitConverter.GetBytes(m_port);
for (int portbyte = 0; portbyte < 4; portbyte++)
{
//#if WinCE
btsa[portbyte + 32] = portbytes[portbyte];
//#else
// btsa[portbyte + 26] = portbytes[portbyte];
//#endif
}
return btsa;
}
#endregion
#region Create
/// <summary>
/// Creates an endpoint from a socket address.
/// </summary>
/// <param name="socketAddress">The <see cref="SocketAddress"/> to use for the endpoint.</param>
/// <returns>An <see cref="EndPoint"/> instance using the specified socket address.</returns>
public override EndPoint Create(SocketAddress socketAddress)
{
if (socketAddress == null)
{
throw new ArgumentNullException("socketAddress");
}
//if a Bluetooth SocketAddress
if (socketAddress[0] == 32)
{
int ibyte;
byte[ addrbytes = new byte
;
for (ibyte = 0; ibyte < 6; ibyte++)
{
//#if WinCE
addrbytes[ibyte] = socketAddress[8 + ibyte];
//#else
// addrbytes[ibyte] = socketAddress[2 + ibyte];
//#endif
}
byte[ servicebytes = new byte[16];
for (ibyte = 0; ibyte < 16; ibyte++)
{
//#if WinCE
servicebytes[ibyte] = socketAddress[16 + ibyte];
//#else
// servicebytes[ibyte] = socketAddress[10 + ibyte];
//#endif
}
byte[ portbytes = new byte[4];
for (ibyte = 0; ibyte < 4; ibyte++)
{
//#if WinCE
portbytes[ibyte] = socketAddress[32 + ibyte];
//#else
// portbytes[ibyte] = socketAddress[26 + ibyte];
//#endif
}
return new BluetoothEndPoint(new BluetoothAddress(addrbytes), new Guid(servicebytes), BitConverter.ToInt32(portbytes, 0));
}
else
{
//use generic method
return base.Create(socketAddress);
}
}
#endregion
add watch:
+ btsa {32:40:{0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,17,0,0,0,0,0,16,128,0,0,128,95,155,52,251,0,0,0,0,0,0,0,0}} System.Net.SocketAddress
socketAddress = {32:40:{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0}}
BluetoothAddress will be 000000000000. Why???