Logo Search packages:      
Sourcecode: libsocket version File versions  Download package

void Network::UdpSocket::connect ( const std::string &  hostname,
int  port 
)

Connect as an UDP client.

Here is an example of an UDP client using libsocket:

 include <stdlib.h>
 include <iostream>
 include <string>
 include "socket/udpsocket.hh"

 int main(int argc, char **argv)
 {
   Network::UdpSocket            client;
   //NetworkUdpSocket            client(Network::V6);
   // For IPV6 mode
   std::string                   str;

   if (argc < 3)
     {
       std::cout << "Use: " << argv[0] << " port hostname" << std::endl;
       exit(0);
     }
   try
     {
       client.connect(std::string(argv[2]), strtol(argv[1], NULL, 10));
       while (str != "quit")
         {
           std::cin >> str;
           client << str;
         }
       client.close();
       exit(0);
     }
   catch (Network::Exception e)
     {
       std::cerr << e;
       exit(1);
     }
 }
 

Definition at line 27 of file udpsocket.cc.

References Network::NetSocket::_bind().

  {
    _port = port;
    _socket = _bind(port, hostname);
  }


Generated by  Doxygen 1.6.0   Back to index