37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
|
|
#include "textgame.hpp"
|
|
#include "driver.hpp"
|
|
#include "drivenengine.hpp"
|
|
|
|
class TNTest : public DrivenEngine {
|
|
public:
|
|
std::unique_ptr<Channel> chan_;
|
|
virtual void event_init() {
|
|
chan_ = new_outgoing_channel("stanford.edu:80");
|
|
chan_->out()->write_bytes("GET /index.html HTTP/1.1\n\n");
|
|
}
|
|
virtual void event_update() {
|
|
std::string input = get_stdio_channel()->in()->read_entire_contents();
|
|
if (input != "") {
|
|
get_stdio_channel()->out()->write_bytes("stdin: ");
|
|
get_stdio_channel()->out()->write_bytes(input);
|
|
}
|
|
if (chan_ != nullptr) {
|
|
if (chan_->closed()) {
|
|
get_stdio_channel()->out()->write_bytes("Connection closed.\n");
|
|
chan_.reset();
|
|
} else {
|
|
chan_->in()->copy_into(get_stdio_channel()->out());
|
|
chan_->in()->clear();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
//TextGame tg;
|
|
TNTest tg;
|
|
driver_drive(&tg);
|
|
}
|