1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include "stdafx.h"
#include "LANcrawler.h"
// Constructor
LANcrawler::Publisher::Publisher(String^ _Datagram, String^ _IP, int _Port)
{
this->_ServerIP = Net::IPAddress::Parse(_IP); // Local IP
this->_ServerPort = _Port; // Local Port
this->_DatagramArray = Text::Encoding::ASCII->GetBytes(_Datagram); // Datagram to send
this->_IPEndPoint = gcnew Net::IPEndPoint(this->_ServerIP, this->_ServerPort); // Building IP end Point Object
this->_UDPsocket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Dgram, ProtocolType::Udp); // Building UDP socket object
}
// Start method
// <- this method start the "flooding thread" ->
void LANcrawler::Publisher::Start()
{
if (this->_FloodingThread == nullptr)
{
this->_FloodingThread = gcnew Thread(gcnew ThreadStart(this, &Publisher::Flood));
this->_FloodingThread->Start(); // Start thread on flood method
}
}
// Flooding method [threaded]
void LANcrawler::Publisher::Flood()
{
while(true)
{
this->_UDPsocket->SendTo(this->_DatagramArray, this->_IPEndPoint);
Threading::Thread::Sleep(50);
// publier ici un evenement !
}
} |