summaryrefslogtreecommitdiffstats
path: root/src/madc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/madc.cpp')
-rw-r--r--src/madc.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/madc.cpp b/src/madc.cpp
index 790baf5..17f6953 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -20,46 +20,43 @@
#include "Net/ClientConnection.h"
#include "Net/IPAddress.h"
#include "Net/Packet.h"
+#include "Common/RequestManager.h"
#include <iostream>
int main() {
Mad::Net::Connection::init();
- Mad::Net::ClientConnection connection;
+ Mad::Common::RequestManager requestManager;
+ Mad::Net::ClientConnection *connection = new Mad::Net::ClientConnection;
try {
- connection.connect(Mad::Net::IPAddress("127.0.0.1", 6666));
+ connection->connect(Mad::Net::IPAddress("127.0.0.1", 6666));
- while(connection.isConnecting()) {
- struct pollfd fd = connection.getPollfd();
+ while(connection->isConnecting()) {
+ struct pollfd fd = connection->getPollfd();
if(poll(&fd, 1, 10000) > 0)
- connection.sendReceive(fd.revents);
+ connection->sendReceive(fd.revents);
}
- connection.send(Mad::Net::Packet(Mad::Net::Packet::TYPE_DEBUG, 0x1234));
- connection.send(Mad::Net::Packet(Mad::Net::Packet::TYPE_DISCONNECT_REQ, 0xABCD));
+ requestManager.registerConnection(connection);
- while(!connection.sendQueueEmpty()) {
- struct pollfd fd = connection.getPollfd();
+ requestManager.sendRequest(connection, Mad::Common::Request::TYPE_PING);
+ requestManager.sendRequest(connection, Mad::Common::Request::TYPE_DISCONNECT);
- if(poll(&fd, 1, 10000) > 0)
- connection.sendReceive(fd.revents);
- }
-
- connection.disconnect();
-
- while(connection.isConnected()) {
- struct pollfd fd = connection.getPollfd();
+ while(connection->isConnected()) {
+ struct pollfd fd = connection->getPollfd();
if(poll(&fd, 1, 10000) > 0)
- connection.sendReceive(fd.revents);
+ connection->sendReceive(fd.revents);
}
}
catch(Mad::Net::Exception &e) {
std::cerr << "Connection error: " << e.what() << std::endl;
}
+ delete connection;
+
Mad::Net::Connection::deinit();
return 0;