36 void receive_data(
const Datagram &data);
37 void receive_line(
string line);
50 _received += data.get_message();
52 size_t newline = _received.find(
'\n', next);
53 while (newline != string::npos) {
56 if (newline > 0 && _received[newline - 1] ==
'\r') {
59 receive_line(_received.substr(last, newline - last));
60 if (next < _received.size() && _received[next] ==
'\r') {
63 newline = _received.find(
'\n', next);
65 _received = _received.substr(next);
69receive_line(
string line) {
70 std::cerr <<
"received: " << line <<
"\n";
72 size_t size = line.size();
73 while (size > 0 && isspace(line[size - 1])) {
76 if (size != line.size()) {
77 line = line.substr(0, size);
94main(
int argc,
char *argv[]) {
96 nout <<
"fake_http_server port\n";
100 int port = atoi(argv[1]);
102 PT(
Connection) rendezvous = cm.open_TCP_server_rendezvous(port, 5);
104 if (rendezvous.is_null()) {
105 nout <<
"Cannot grab port " << port <<
".\n";
109 nout <<
"Listening for connections on port " << port <<
"\n";
112 listener.add_connection(rendezvous);
117 reader.set_raw_mode(1);
118 writer.set_raw_mode(1);
120 bool shutdown =
false;
123 while (listener.new_connection_available()) {
127 if (listener.get_new_connection(rv, address, new_connection)) {
128 nout <<
"Got connection from " << address <<
"\n";
129 reader.add_connection(new_connection);
130 clients.insert(Clients::value_type(new_connection, ClientState(new_connection)));
138 nout <<
"Lost connection from "
139 << connection->get_address() <<
"\n";
140 clients.erase(connection);
146 while (reader.data_available()) {
148 if (reader.get_data(datagram)) {
149 PT(
Connection) client = datagram.get_connection();
150 Clients::iterator ci = clients.find(client);
151 if (ci == clients.end()) {
152 nout <<
"Received data from unexpected client " << (
void *)client
155 ClientState &state = (*ci).second;
156 state.receive_data(datagram);
PT(Connection) open_TCP_client_connection(const std bool close_connection(const PT(Connection) &connection)
Terminates a UDP or TCP socket previously opened.
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
Represents a single TCP or UDP socket for input or output.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound.
A specific kind of Datagram, especially for sending across or receiving from a network.
This flavor of ConnectionListener will queue up all of the TCP connections it established for later d...
This flavor of ConnectionManager will queue up all of the reset-connection messages from the Connecti...
bool reset_connection_available() const
Returns true if one of the readers/writers/listeners reported a connection reset recently.
bool get_reset_connection(PT(Connection) &connection)
If a previous call to reset_connection_available() returned true, this function will return informati...
This flavor of ConnectionReader will read from its sockets and queue up all of the datagrams read for...
This is our own Panda specialization on the default STL map.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.