×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    Oulu
    Posts
    132

    How to open TCP socket using spesific network interface

    Hi,

    I need to choose which network interface my socket uses. The device might have many interfaces open simultaneously (for example wlan, 3g streaming QOS, 3g browsing QOS, 3g mms) and I want my application to choose which one to use for a new socket.

    In Symbian C++ RSocket takes reference to RConnection in open method.

    In Qt QTcpSocket doesn't seem to have any obvious way to force it to use specific interface.
    QUdpSocket does have bind method and it looks like it might be transfered to QAbstractSocket in future (http://qt.gitorious.org/qt/qt/merge_requests/2373).

    While waiting this improvement, are there any workaround?

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to open TCP socket using spesific network interface


  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    Oulu
    Posts
    132

    Re: How to open TCP socket using spesific network interface

    Thanks for fast reply.

    Perhaps I should be more specific. I'm trying to create tcp socket for a client.

    Could this be achieved with QTcpServer?

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to open TCP socket using spesific network interface

    You can impact interface being used by sockets with help of establishing QNetworkSession.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Location
    Oulu
    Posts
    132

    Re: How to open TCP socket using spesific network interface

    Quote Originally Posted by divanov View Post
    You can impact interface being used by sockets with help of establishing QNetworkSession.
    I'm aware that using QNetworkSession I can 'rise up' interfaces. However when there are many interfaces active, I don't know how to specify which interface new socket uses.

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to open TCP socket using spesific network interface

    Again, if you open a session using configuration for certain interface, then according to documentation all sockets of your application will be using that interface.

  7. #7
    Registered User
    Join Date
    Mar 2003
    Location
    Oulu
    Posts
    132

    Re: How to open TCP socket using spesific network interface

    Quote Originally Posted by divanov View Post
    Again, if you open a session using configuration for certain interface, then according to documentation all sockets of your application will be using that interface.
    Yes, this propably applies if there are only one active interface.

    If I have two open connections/sessions/active interfaces. One uses cellular network (ex. 3G) and another uses WLAN.
    I'm not aware of any means of telling a new QTcpSocket that use this interface instead of this one.

    Or is there a limitation with Qt that only one interface can be active simultaneously. Symbian can handle number of simultaneous interfaces over cellular network in addition to wlan. Windows and Linux can have multiple network cards/interfaces...
    Last edited by Roose; 2011-02-04 at 14:02.

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to open TCP socket using spesific network interface

    Active interfaces and configurations associated with them are not related to your application directly. Do you explicitly create more than one network session in your application?

  9. #9
    Registered User
    Join Date
    Mar 2003
    Location
    Oulu
    Posts
    132

    Re: How to open TCP socket using spesific network interface

    Quote Originally Posted by divanov View Post
    Active interfaces and configurations associated with them are not related to your application directly. Do you explicitly create more than one network session in your application?
    Eventhought my application activates only one interface, it must be able to handle situation where user has created more than one. My application must be able to use the accesspoint previously defined and nothing else.

  10. #10
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to open TCP socket using spesific network interface

    Quote Originally Posted by Roose View Post
    Eventhought my application activates only one interface, it must be able to handle situation where user has created more than one. My application must be able to use the accesspoint previously defined and nothing else.
    Then what is the problem?

  11. #11
    Registered User
    Join Date
    Mar 2003
    Location
    Oulu
    Posts
    132

    Re: How to open TCP socket using spesific network interface

    Quote Originally Posted by divanov View Post
    Then what is the problem?
    The problem is that when I create a new QTcpSocket I don't know how to bind it to use spesific interface

  12. #12
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to open TCP socket using spesific network interface

    Quote Originally Posted by Roose View Post
    The problem is that when I create a new QTcpSocket I don't know how to bind it to use spesific interface
    The solution was mentioned in comment #6.
    Last edited by divanov; 2011-02-04 at 14:34.

  13. #13
    Registered User
    Join Date
    Mar 2003
    Location
    Oulu
    Posts
    132

    Re: How to open TCP socket using spesific network interface

    Quote Originally Posted by divanov View Post
    The solution was mentioned in comment #6.
    I have seen the light!

    The whole idea of having application wide and only application wide session which would be used by all sockets was mind blowing. My brain just couldn't handle the idea of Socket using specific access point without getting direct reference to it.

    Thanks for your perseverance!
    Last edited by Roose; 2011-02-07 at 08:49.

  14. #14
    Regular Contributor
    Join Date
    Apr 2010
    Posts
    79

    Re: How to open TCP socket using spesific network interface

    madam, I think this is the way to open a tcp socket.

    void MainWindow::connectAP()
    {
    const bool canStartIAP = (configManager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces);
    QNetworkConfiguration cfg = configManager.defaultConfiguration();
    if(!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) {
    QMessageBox::information(this, tr("Network"), tr("No Access point"));
    return;
    }
    session = new QNetworkSession(cfg, this);
    session->open();
    session->waitForOpened(-1);
    //session->accept();
    }


    tcpSocket = new QTcpSocket(this);
    blockSize = 0;
    tcpSocket->abort();
    tcpSocket->connectToHost(HostName, 57);

  15. #15
    Registered User
    Join Date
    Mar 2003
    Location
    Oulu
    Posts
    132

    Re: How to open TCP socket using spesific network interface

    Quote Originally Posted by divanov View Post
    Then what is the problem?
    I just realized that in near future there might be a case where I should be able to open specific sockets via WLAN and 3G simultaneously.

    Can it be done...?


    Quote Originally Posted by LesterPH View Post
    madam, I think this is the way to open a tcp socket.
    I believe this is what divanov ment.

    btw, madam-part really fondles my manhood ;D
    Last edited by Roose; 2011-02-08 at 09:25.

Similar Threads

  1. How to get network interface ip address?
    By abovesun in forum Open C/C++
    Replies: 1
    Last Post: 2010-11-21, 07:36
  2. How to set different TCP options when creating a socket
    By siddhartha84 in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2007-03-23, 15:34
  3. how to send data in to a tcp socket
    By tatoo_00_44 in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2007-03-07, 11:54
  4. How to make TCP socket works on Emulator?
    By cs_lcmaa in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 1970-01-01, 01:00

Posting Permissions

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