.NET Components for Mobility

localEP?

Last post 07-23-2008 6:15 AM by PeterFoot. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-22-2008 5:13 AM

    • George
    • Top 75 Contributor
    • Joined on 07-22-2008
    • Posts 8

    localEP?

    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 byteDevil;
                    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???

     

    Filed under: , ,
  • 07-22-2008 5:10 PM In reply to

    Re: localEP?

    Eeeeeh lots of source code there.

    I dom't understand why you think there should be anything different.  It all looks consistent to me.  The address bytes are read from bytes 9 thru 14 (8-13 zero-indexed) which are all zeros....

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 07-23-2008 6:15 AM In reply to

    Re: localEP?

    Firstly if you are using the code independently of the compiled dll you'll need to add the WinCE compilation constant to your project to ensure the correct code paths are used - this is much easier than commenting out all the #ifs

    Perhaps you can put this in context - what code are you calling to end up with this empty device address, I suspect that it has nothing to do with the serialization/de-serialization of the socketaddress...

    Peter

    Peter Foot
    Microsoft Device Application Development MVP
    www.peterfoot.net | www.inthehand.com
Page 1 of 1 (3 items)
Copyright © 2001-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.