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/>.
21 #include "nel/misc/types_nl.h"
22 #include "nel/misc/debug.h"
23 #include "nel/misc/mem_stream.h"
25 #include "nel/net/inet_address.h"
26 #include "nel/net/udp_sim_sock.h"
34 using namespace NLMISC
;
35 using namespace NLNET
;
42 int main (int argc
, char **argv
)
46 nlinfo ("%s send udp datagram to a specific port to test a connection between client and server", argv
[0]);
47 nlinfo ("usage: <ip_address> <port>");
51 CUdpSimSock
*UdpSock
= NULL
;
52 UdpSock
= new CUdpSimSock( false );
55 UdpSock
->connect (CInetAddress (argv
[1], atoi(argv
[2])));
59 nlwarning ("Cannot connect to remote UDP host: %s", e
.what());
63 uint8
*packet
= new uint8
[1000];
71 uint32 size
= msgout
.length();
72 UdpSock
->send (msgout
.buffer(), size
);
73 nldebug ("Sent UDP datagram size %d to %s", size
, UdpSock
->localAddr().asString().c_str());
75 while (UdpSock
->dataAvailable())
80 UdpSock
->receive (packet
, psize
);
81 nldebug ("Received UDP datagram size %d bytes from %s", psize
, UdpSock
->localAddr().asString().c_str());
83 catch ( Exception
& e
)
85 nlwarning ("Received failed: %s", e
.what());