1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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 3 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.
29 // We're building a server, using the NeL Service framework
30 #include "nel/net/service.h"
31 using namespace NLNET
;
35 * Callback function called when receiving a "PING" message
38 * - msgin: the incoming message (coming from a client)
39 * - from: the "sockid" of the sender client
40 * - server: the CCallbackNetBase object (which really is a CCallbackServer object, for a server)
42 * Input (expected message from a client): PING
43 * - uint32: ping counter
45 * Output (sent message to the ping server): PONG
46 * - uint32: ping counter
48 void cbPing( CMessage
& msgin
, TSockId from
, CCallbackNetBase
& server
)
53 msgin
.serial( counter
);
56 CMessage
msgout( "PONG" );
57 msgout
.serial( counter
);
58 server
.send( msgout
, from
);
60 nlinfo( "PING -> PONG" );
65 * Callback array for messages received from a client
67 TCallbackItem CallbackArray
[] =
73 // We use IService directly, no need to inherit from it
77 * Declare a service with the class IService, the names "PS" (short) and "ping_service" (long).
78 * The port is automatically allocated (0) and the main callback array is CallbackArray.
80 NLNET_OLD_SERVICE_MAIN( IService
, "PS", "ping_service", 0, CallbackArray
, "", "" )