socket.cpp

Go to the documentation of this file.
00001 /*
00002  * socket.cpp
00003  *
00004  *  Created on: Jan 12, 2012
00005  *      Author: sushil
00006  */
00007 #include <iostream>
00008 #include <boost/asio.hpp>
00009 
00010 #include <socket.h>
00011 #include <DEBUG.h>
00012 
00013 using namespace FastEcslent;
00014 
00015 
00016 boost::asio::ip::udp::socket* FastEcslent::makeUDPBroadcastSocket (){
00017 
00018                 boost::asio::io_service netService;
00019                 /*
00020                 udp::endpoint anyEndpoint(udp::v4(), (unsigned short) port);
00021                 udp::endpoint any(boost::asio::ip::address_v4::any(), port);
00022                 udp::endpoint recFrom;
00023                 //std::cout << "Listener Endpoint Address: " << anyEndpoint.address().to_string() << " Port: " << anyEndpoint.port() << std::endl;
00024                 //std::cout << "Listener Any Address: " << any.address().to_string() << " Port: " << anyEndpoint.port() << std::endl;
00025 
00026                  */
00027 
00028                 boost::asio::ip::udp::socket* socket;
00029                 try {
00030                         socket = new boost::asio::ip::udp::socket(netService);
00031                         socket->open(boost::asio::ip::udp::v4());
00032                         DEBUG(std::cout << "Opened Socket" << std::endl;)
00033 
00034                         boost::asio::socket_base::reuse_address option1(true);
00035                         socket->set_option(option1);
00036                         boost::asio::socket_base::broadcast option2(true);
00037                         socket->set_option(option2);
00038 
00039                         boost::asio::socket_base::receive_buffer_size option(65536);
00040                         socket->set_option(option);
00041                         boost::asio::socket_base::receive_buffer_size option3;
00042                         socket->get_option(option3);
00043 
00044 
00045                         DEBUG(std::cout << "Socket receive buffer size: " << option3.value() << std::endl;)
00046                 } catch (std::exception &e) {
00047                         DEBUG(std::cerr << "Exception in creating socket: " << e.what() << std::endl;)
00048                 }
00049                 return socket;
00050 }
00051 
00052 

Generated on Fri Dec 13 14:54:18 2013 for FastECSLent by  doxygen 1.5.4