Connect a two-player QML game through Wifi

  • I started learning QML and after a while wanted to test myself through writing a good QML app by what I'd learnt up to that time.
    It's my app, called Pingpong.


    It embraces six QML files: main.qml, Racket.qml, Ball.qml, WinBox.qml, Counter.qml and Light.qml:


    It's good, has an icon and works fine on Android devices.

    For the second major version, I want to develop it so that the game can connect by Wifi and two players can play the game installed on their smartphones through a shared Wifi.

    Actually, @J.HILK suggested that I consider that for the next progress in the app.

    Now, what to do for that goal? Where should I start, please?

  • Lifetime Qt Champion


    Don't get hellbent on WiFi rather on network in general.

    You can start by studying the Qt's network related example, specifically the TCP related ones. @VRonin's chat example will also be of interest (not so much for the chat part itself but for the network related stuff).

    Next question is whether you want to have a server somewhere or the game instances being able to handle each other.

  • Thanks.
    Wouldn't it be easier if I used Bluetooth instead of Wifi?
    I'm myself new in QML I fear the stuff relating to networking (and Wifi) are too complex for this time of me. Aren't they, please?

  • Moderators

    @tomy hi,

    First of:
    Happy new year, if you follow the gregorian calendar.

    I personlly find Networking(LAN and WLAN) a good bit easier to use and implement than Bluetooth, but that just my opninion.

    What @SGaist says it true, TCPSockets (with or without a server) is probably the way you want to go.

    Here are some helpfull links.

    Fortune Client example
    Fortune Server example

    install the client on one phone the sever on the other and see if you manage a connection, should be relatively easy, but can be a challenge. At first, do not try to cross OS's - for example windows <->Android, because that can be a lot more complicated.

    Video Turotial QTcpSockets

  • Hello,
    I'd use the new Qt Remote Objects. They hide away all the network stuff so you can focus on the game.

    citation from the doc:
    "Qt Remote Objects (QtRO) is an inter-process communication (IPC) module developed for Qt. The idea is to extend Qt's existing functionalities to enable an easy exchange of information between processes or computers."

    QtRO Documentation

    cheers wink

Log in to reply