summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/pingpong/doc/src/pingpong.qdoc
blob: 0e82a71af095f0eee9e709f018885222d9eaeb04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.  Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example pingpong
    \title Bluetooth QML Ping Pong example
    \brief A QML example showing Bluetooth communication.

    The Bluetooth QML Ping Pong example presents the socket communication between two
    Bluetooth devices. The basic concept is the ping pong game where two players
    communicate via sockets.

    \image intro.png

    \include examples-run.qdocinc

    At the beginning, the user selects the role. One device acts as a server and the second
    one as a client. After selecting the role, adjustments to the screen size are done
    (two devices might have different screen sizes). The server side starts a service named
    "PingPong server".

    \snippet pingpong/pingpong.cpp Starting the server

    On the client side, the full service discovery on the nearby Bluetooth devices is done.

    \snippet pingpong/pingpong.cpp Searching for the service

    When the ping pong service is discovered, the client connects to the server using the socket.

    \snippet pingpong/pingpong.cpp Connecting the socket

    On the server side, the connected signal is emitted initiating that the client is connected.
    The necessary signals and slots on the server side are connected.

    \snippet pingpong/pingpong.cpp Initiating server socket

    The game starts after the devices are connected and the screen is adjusted.

    \snippet pingpong/pingpong.cpp Start the game

    The server updates the ball direction and coordinates. The coordinates of pedals are sent
    to each other every 50ms.

    \snippet pingpong/pingpong.cpp Updating coordinates

    The coordinates are updated and exchanged via sockets. As presented, the server sends its
    pedal's y coordinate and the ball coordinates whereas, the client sends only its pedal
    y coordinate.

    \snippet pingpong/pingpong.cpp Checking the boundaries

    In the code above, it was shown how the server checks whether the ball has reached
    the boundaries of the board. In the case of the goal, the server updates
    the results via its socket.

    \image intro1.png

*/