// Copyright 2005, The Tanoshi development team // Assigned to public domain, Use as you wish withou restriction. #include #include #include #include #include #include #include #include class main_proc : public sigc::trackable { public: Tanoshi::UDPSocket udpsocket; Tanoshi::EventManager eventmanager; void run(); void connected(); void datatoread(); void error(int i); }; void main_proc::run() { udpsocket.setEventManager(&eventmanager); udpsocket.error.connect(sigc::mem_fun(this, &main_proc::error)); udpsocket.connected.connect(sigc::mem_fun(this, &main_proc::connected)); udpsocket.readyRead.connect(sigc::mem_fun(this, &main_proc::datatoread)); udpsocket.listen(); udpsocket.bind(Tanoshi::HostAddress("127.0.0.1"), 1515); for(;;) { eventmanager.processEvent(); eventmanager.sleep(); } } void main_proc::connected() { printf("Connected to host...\n"); udpsocket.write(Tanoshi::HostAddress("127.0.0.1"), 2525, "Ping"); udpsocket.write(Tanoshi::HostAddress("127.0.0.1"), 2525, "Ping"); udpsocket.write(Tanoshi::HostAddress("127.0.0.1"), 2525, "Ping"); udpsocket.write(Tanoshi::HostAddress("127.0.0.1"), 2525, "Ping"); udpsocket.write(Tanoshi::HostAddress("127.0.0.1"), 2525, "Ping"); } void main_proc::datatoread() { unsigned int a = udpsocket.packetsAvailable(); for(int i = 0; i < a; i++) { std::auto_ptr st((Tanoshi::UDPPacket *)udpsocket.read()); Tanoshi::ByteArray ba = st->data(); ba.append((char)0); printf("Recieved From: %s:%d\n", st->hostAddress().toString().c_str(), st->port()); printf("%s\n", ba.data()); } } void main_proc::error(int i) { printf("SOCKET ERROR: %d\n", i); } int main() { class main_proc test; test.run(); }