| 31 | { |
| 32 | |
| 33 | void on_connect ( |
| 34 | std::istream& in, |
| 35 | std::ostream& out, |
| 36 | const std::string& foreign_ip, |
| 37 | const std::string& /*local_ip*/, |
| 38 | unsigned short /*foreign_port*/, |
| 39 | unsigned short /*local_port*/, |
| 40 | uint64 /*connection_id*/ |
| 41 | ) |
| 42 | { |
| 43 | // The details of the connection are contained in the last few arguments to |
| 44 | // on_connect(). For more information, see the documentation for the |
| 45 | // server_iostream. However, the main arguments of interest are the two streams. |
| 46 | // Here we also print the IP address of the remote machine. |
| 47 | cout << "Got a connection from " << foreign_ip << endl; |
| 48 | |
| 49 | // Loop until we hit the end of the stream. This happens when the connection |
| 50 | // terminates. |
| 51 | while (in.peek() != EOF) |
| 52 | { |
| 53 | // get the next character from the client |
| 54 | char ch = in.get(); |
| 55 | |
| 56 | // now echo it back to them |
| 57 | out << (char)toupper(ch); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | }; |
| 62 | |