Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / samples / net / net_layer4 / ping_service.cpp
blob12e49b6f35bd81bd6b44053c41f1f2a01c1782e5
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * Layer 4 and Service example, ping server.
21 * This ping service expects pings, sends pongs back.
23 * To run this program, ensure there is a file "ping_service.cfg"
24 * containing the location of the naming service (NSHost, NSPort)
25 * in the working directory. The naming service must be running.
27 * DEPRECATED: You should use layer5 (take a look in the layer5 sample directory)
32 // We're using the NeL Service framework, and layer 4
33 #include "nel/net/service.h"
34 using namespace NLNET;
38 * Callback function called when receiving a "PING" message
40 * Arguments:
41 * - msgin: the incoming message (coming from a client)
42 * - from: the "sockid" of the sender client
43 * - server: the CCallbackNetBase object (which really is a CCallbackServer object, for a server)
45 * Input (expected message from a client): PING
46 * - uint32: ping counter
48 * Output (sent message to the ping server): PONG
49 * - uint32: ping counter
51 void cbPing( CMessage& msgin, TSockId from, CCallbackNetBase& server )
53 uint32 counter;
55 // Input
56 msgin.serial( counter );
58 // Output (uses layer 4 but this is not really necessary, see server.cpp in layer 3 example)
59 CMessage msgout( "PONG" );
60 msgout.serial( counter );
61 CNetManager::send( "PS", msgout, from );
63 nlinfo( "PING -> PONG %u", counter );
68 * Callback array for messages received from a client
70 TCallbackItem CallbackArray[] =
72 { "PING", cbPing }
76 // We use IService directly, no need to inherit from it
80 * Declare a service with the class IService, the names "PS" (short) and "ping_service" (long).
81 * The port is automatically allocated (0) and the main callback array is CallbackArray.
83 NLNET_OLD_SERVICE_MAIN( IService, "PS", "ping_service", 0, CallbackArray, "", "" )