summaryrefslogtreecommitdiff
path: root/examples/bluetooth/pingpong/doc/src/pingpong.qdoc
blob: a91b8f2e95099386c3ba574f86f92bc862b79f3f (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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \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 qmlpingpong_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. 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 10ms.

    \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 case of a collision with a pedal, a convex surface
    is simulated. The part of the velocity normal to the simulated surface is inverted
    and increased by 10% to speed up the game. In the case of the goal, the server updates
    the results via its socket.

    \image intro1.png

*/