1 /*
2 * Portable Agile C++ Classes (PACC)
3 * Copyright (C) 2001-2003 by Marc Parizeau
4 * http://manitou.gel.ulaval.ca/~parizeau/PACC
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Contact:
21 * Laboratoire de Vision et Systemes Numeriques
22 * Departement de genie electrique et de genie informatique
23 * Universite Laval, Quebec, Canada, G1K 7P4
24 * http://vision.gel.ulaval.ca
25 *
26 */
27
28 /*!
29 * \file PACC/Socket/ConnectedUDP.cpp
30 * \brief Class methods for the portable connected %UDP client.
31 * \author Marc Parizeau, Laboratoire de vision et systèmes numériques, Université Laval
32 * $Revision: 1.6.2.1 $
33 * $Date: 2007/09/10 18:24:09 $
34 */
35
36 #include "Socket/ConnectedUDP.hpp"
37
38 using namespace std;
39 using namespace PACC;
40
41 /*! \brief Receive string datagram from connected (UDP) server.
42
43 This function waits for a datagram from the connected peer socket, or until time out. It returns the received datagram through output parameter \c outDatagram. Any error raises a Socket::Exception. For instance, it throws an exception with code Socket::eTimeOut if the timeout period expires before reception of any datagram. The timeout period can be changed using function Port::setSockOpt with parameter Socket::eRecvTimeOut.
44 */
receiveDatagram(std::string & outDatagram)45 void Socket::ConnectedUDP::receiveDatagram(std::string& outDatagram)
46 {
47 outDatagram.resize((unsigned int) getSockOpt(eRecvBufSize));
48 unsigned int lRecv = receive(&outDatagram[0], outDatagram.size());
49 outDatagram.resize(lRecv);
50 }
51
52 /*! \brief Send datagram message to connected (UDP) server.
53 \attention Maximum datagram size defaults to 1024 bytes.
54
55 This function sends datagram string \c inDatagram to the connected peer socket. Any error raises a Socket::Exception. For instance, it throws an exception with code \c Socket::eTimeOut if the datagram cannot be sent before the time out period expires. The time out period can be changed using function \c Port::setSockOpt with parameter \c Socket::eSendTimeOut.
56 */
sendDatagram(const string & inDatagram)57 void Socket::ConnectedUDP::sendDatagram(const string& inDatagram)
58 {
59 send(inDatagram.data(), inDatagram.size());
60 }
61