Results 1 to 5 of 5

Thread: P2P ideas please....

  1. #1
    Join Date
    Nov 2006
    Posts
    41
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default P2P ideas please....

    Hi there, im developing a simple game and i it should be p2p, so as i know about sockets in Qt i can use for each peer application a QTcpSocket for handling messages from the other peer and use QTcpServer to send messages and to stay connected with the peer, will this work ok? for sending/receiving messages from the peer? the QTcpSocket should just connect with ip and port of the other peer QTcpServer object isn't it?
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: P2P ideas please....

    Yes and no If you make a tcp server and a tcp client then it's hard to call it p2p. But apart from that what you say is true.

  3. #3
    Join Date
    Nov 2006
    Posts
    41
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: P2P ideas please....

    uhm well yep i guess its not the best implementation but this works well for a p2p approach doesnt it?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: P2P ideas please....

    "It works."

    In general p2p tends to use UDP rather than TCP as then you can really speak about peers. But there is nothing wrong in using TCP.

  5. #5
    Join Date
    Nov 2006
    Posts
    41
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: P2P ideas please....

    Indeed i'll be using udp sockets better since i prefer to send a broadcast to players looking for a challenger and i will be sending lots of messages however i dont know how to send and receive requests for playing ignoring my own message, i have this...

    Qt Code:
    1. void startupDialog::readDatagrams(){
    2. QHostAddress *remoteHost = new QHostAddress;
    3. while( udpSocket->hasPendingDatagrams() ){
    4. QByteArray datagram;
    5. datagram.resize(udpSocket->pendingDatagramSize());
    6. udpSocket->readDatagram(datagram.data(), datagram.size(), remoteHost);
    7.  
    8. if( qstrcmp(datagram.data(), "//SearchingPlayers") == 0 && remoteHost->toString() != ??? WTF ??? ){
    9. playersFound++;
    10. }
    11. statusLabel2->setText(QString("PlayersFound :: %1").arg(playersFound));
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    And for the sender...
    Qt Code:
    1. void startupDialog::sendDatagrams(){
    2. statusLabel->setText("Looking for players...");
    3. QByteArray datagram = "//SearchingPlayers";
    4. udpSocket->writeDatagram(datagram.data(), datagram.size(),
    5. QHostAddress::Broadcast, 45454);
    6. }
    To copy to clipboard, switch view to plain text mode 
    I dont know if this is the best way to find players but i want to avoid the message to myself so i dont know what to write instead of "WTF" can someone help? thanks

Similar Threads

  1. Any ideas on determining cpu load in run-time?
    By a550ee in forum Qt Programming
    Replies: 3
    Last Post: 24th November 2006, 09:38
  2. Ideas about how to implement Undo and Redo actions?
    By pir in forum General Discussion
    Replies: 3
    Last Post: 21st July 2006, 10:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.