/* * C++ sockets on Unix and Windows * Copyright (C) 2002 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "PracticalSocket.h" // For UDPSocket and SocketException #include // For cout and cerr #include // For atoi() #ifdef WIN32 #include // For ::Sleep() void sleep(unsigned int seconds) {::Sleep(seconds * 1000);} #else #include // For sleep() #endif using namespace std; int main(int argc, char *argv[]) { if ((argc < 3) || (argc > 4)) { // Test for correct number of arguments cerr << "Usage: " << argv[0] << " \n"; exit(1); } string destAddress = argv[1]; // First arg: destination address unsigned short destPort = atoi(argv[2]); // Second arg: destination port char* sendString = argv[3]; // Third arg: string to broadcast try { UDPSocket sock; // Repeatedly send the string (not including \0) to the server for (;;) { sock.sendTo(sendString, strlen(sendString), destAddress, destPort); sleep(3); } } catch (SocketException &e) { cerr << e.what() << endl; exit(1); } return 0; }