×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    318

    cannot create TBTSockAddr object from CArrayFixSeg<class TSockAddr> element??

    Hello ppl,

    Funny problem.

    I have an array filled with TBTSockAddr values which are inserted when i perform my discovery. My array is defined like this:
    CArrayFixSeg<TSockAddr>* sockAddrArray

    Later i wish to form a connection, but first i need to supply the Socket.Connect() function with a TBTSockAddr from the array.

    So just to test the code, ... i do this:

    TBTSockAddr iBTSockAddr(sockAddrArray[0]);

    I get the following error:

    error C2664: '__thiscall TBTSockAddr::TBTSockAddr(const class TSockAddr &)' : cannot convert parameter 1 from 'class CArrayFixSeg<class TSockAddr>' to 'const class TSockAddr &'
    Reason: cannot convert from 'class CArrayFixSeg<class TSockAddr>' to 'const class TSockAddr'
    No constructor could take the source type, or constructor overload resolution was ambiguous

    Any idea anyone?

    If its of any help, here's how i insert values into my array:

    TSockAddr sockAddr = static_cast<TSockAddr>(entry().iAddr);
    aSockAddrArray.InsertL(i, sockAddr);

  2. #2
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Berlin, Germany
    Posts
    58
    i'm not 100% sure about this, but wouldn't you have to "dereference" the sockAddrArray before accesing it? it's a pointer(!) to a CArray, right?

    funny thing is: i think i never used a CArray before. hmm.. i'm always using RArrays.. or RPointerArrays.. well.. doesn't matter here.. i guess.. :-)

    anyway.. (*sockAddrArray)[ 0 ] should do the trick..

    regards,

    tfdj

  3. #3
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    318

    You're a genius!

    Thanks alot DJ,

    I didn't think that was the problem, coz i have another CArrayFixSeg array, but contains different data:
    CArrayFixSeg<THostName>* nameArray;

    //in some loop somewhere
    THostName hostName = entry().iName;
    aNameArray.InsertL(i, hostName);

    //I can do the following without using (*aNameArray)[i])
    TBuf<20> temp;
    temp.Append(aNameArray[i]);

    why is this so?

    btw, i'm not 100% sure bout this too, but i think dereferencing refers to '&'(dereference operator, while reference operator is *

    oh well
    Thanks all the same.
    Last edited by advocatee; 2003-11-27 at 18:56.

  4. #4
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Berlin, Germany
    Posts
    58
    i'm not a c++ expert.. i guess it has something to do with overloading of the [] operator.. does it? :-\

    in your case i think the const/non-const is the problem.. or not the problem.. if you Append to a TBuf the object you append must not be const..

    well.. not sure.. something like this!? :-)

    tfdj

  5. #5
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    318

    Port vs Channel

    Dj,

    Thanks, I do hope u have time for one more question..

    I can now make connections , but have some issue about the ports, which makes my connections funny.

    Lets say i have an advertising server, and a connecting client.
    This is some code from the server, :

    // Get a channel to listen on - same as the socket's port number
    TInt channel;
    User::LeaveIfError(
    iListeningSocket.GetOpt(KRFCOMMGetAvailableServerChannel, KSolBtRFCOMM, channel)
    );

    1) Is the 'channel' the 'port'? or are they 2 different entities but with are being assigned the same value?

    2) Does the port specified in the TSockAddr on the client have to be the same as the port number on the Server? Are they even related?
    If they need to be the same i have no idea how to get the server port for the client to use. Examples usually use fixed ports for the client, e.g:

    Client Code:
    User::LeaveIfError(iSendingSocket.Open(iSocketServer, _L("RFCOMM")));

    const TUint KRfcommChannel = 1;
    iBTSockAddr.SetBTAddr(iBTSockAddr.BTAddr());
    iBTSockAddr.SetPort(KRfcommChannel);
    iSendingSocket.Connect(iBTSockAddr,iStatus);

    I'm blur.. i don't know what my solutions are.

  6. #6
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    318
    The BTP2P example uses

    TBTSockAddr address;
    address.SetBTAddr(iServiceSearcher->BTDevAddr());
    address.SetPort(iServiceSearcher->Port());

    To get the remote port, i guess.

    i'm using rhostresolver

  7. #7
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Berlin, Germany
    Posts
    58
    and i don't know what your question is.. :-)

    honestly, i have no clue about the channels/port thing.. i never used it.. i never needed it.. why do you need it?

    to put it another way: your last post contains exactly the code i am using..

    tfdj
    Last edited by The.French.DJ; 2003-11-27 at 20:13.

  8. #8
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    318
    hmm

    I'm using RHostResolver to automate discoveries, not RNotifier,,
    I know that BTP2P has some way of getting the remote port by using
    void CMessageServiceSearcher::FoundElementL(TInt aKey, CSdpAttrValue& aValue)
    {
    User::InfoPrint(_L("FoundElement"));
    __ASSERT_ALWAYS(aKey == static_cast<TInt>(KRfcommChannel), Panic(EBTServiceSearcherProtocolRead));

    iPort = aValue.Uint();
    }

    I'm not sure how it works anyway..

    As far as i know, RHostResolver returns a TNameEntry object, rather than a responseparamspackage thing which comes with RNotifier. The TNameEntry apparently doesn't have the that the port that the remote device is using . I'm not sure how to get this port.

    Most of the time my phone(if it is the server) is dynamically assinged the listening port = 4, using the GetOpt command. There was once it was 3. The emulator, if it becomes the server ,is always dynamically assigned the listening port 1.
    I'm worried that if i give the client a fixed port to connect to (e.g: 4) the server, things may not workout all the time. I could copy paste the code from BTP2P and get the remote port (however it does it), but in my case i'm using RHostResolver.

    So i have to set my stuff like this, using a fixed port for client to connect to:

    TBTSockAddr iBTSockAddr(tNameEntryObj().iAddr);
    const TUint KRfcommChannel = 4;
    iBTSockAddr.SetBTAddr(iBTSockAddr.BTAddr());
    iBTSockAddr.SetPort(KRfcommChannel);
    iSendingSocket.Connect(iBTSockAddr,iStatus);

    If i had the actual server port i could use
    iBTSockAddr.SetPort(serverPort);


    =)

  9. #9
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    318
    I think i'll just make the port standard all around. Since the phone usually uses port 4...

    I'm now using port 4, so even when i advertise i don't use GetOpt to get a port.

    I'll just

    TInt channel; channel = 4;
    /*
    User::LeaveIfError(
    iListeningSocket.GetOpt(KRFCOMMGetAvailableServerChannel, //KSolBtRFCOMM, channel)
    );
    */

    This way my emulator can connect to my phone and vice versa. The old situation was:

    dynamic GetOpt assignments:
    Emulator always advertises and listens on port 1.
    Phone usually advertises and listens on port 4.

    now:

    Emulator and phone are forced to always advertise then listen on port 4.

    do i make sense? =p

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    27
    Suppose that I've written a background server that uses RfComm. This does it the correct way, and is usually allocated channel 4.

    Now someone tries to run your application on a phone that is already running my application. Are you going to tell them that they have to close my app, start your app, and then they can start my app again?

    What if we both hardcoded our apps to be on channel 4?

  11. #11
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    318
    steve,

    Yeap i did see that problem.. so i came up with yet another idea.
    Assume my server is now dynamically assigning the rfcomm channel/port with GetOpt. I can insert that port in my service description for the remote device to parse and connect to.
    This way they'll always be connecting to the correct ports.

    I've another small prob, lets say I have successfully connected my Client to the remote Server via sockets. This only allows one way transfer of data.

    I'm planning to do some full duplexing here, so i want my client,after connecting, to tell the server to connect back to it, to the client's listening port(probably a separate active object). That is, i will then have 2 active objects running on the client (server will also have 2 then).

    One for connecting and sending data,
    One for listening and receiving conections.
    **Tada!.. 2 way communication!

    **Client already connected to Server. Server needs client port and BT device addr toconnect back..right?***

    I can get the Client's listening port value to be sent to the Server to be parsed, but if i'm not wrong the server also needs the Client device address(TBTDevAddr). Example code for server's connecting socket:

    iBTSockAddr.SetBTAddr(Where to get this value?); //clients device addr (TBTDevAddr)
    iBTSockAddr.SetPort(ClientPort);//client can send this over to server...
    iSendingSocket.Connect(iBTSockAddr,iStatus);

    How can i get the Client's local device address(TBTDevAddr) for the Server to connect to? (at this point the client has already connected itself to the server)

    I hope u understand my problem so far.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×