diff --git a/examples/packet.cpp b/examples/packet.cpp deleted file mode 100644 index 1897773..0000000 --- a/examples/packet.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "frnetlib/Packet.h" - - -int main() -{ - fr::Packet packet; - std::vector> bob = {{1, 2}, {3, 4}}; - packet << bob; - bob.clear(); - - packet >> bob; - std::cout << bob[0].first << ", " << bob[0].second << ", " << bob[1].first << ", " << bob[1].second << std::endl; -} \ No newline at end of file diff --git a/examples/tcpsocket_client.cpp b/examples/tcpsocket_client.cpp deleted file mode 100644 index 41b7816..0000000 --- a/examples/tcpsocket_client.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include - -using namespace std; - - - -int client_round(fr::TcpSocket& socket) -{ - cout << "CLIENT:Going to send something ..." << endl; - - //Receive the request - fr::Packet packet; - packet << "Hello there, I am" << (float)1.2 << "years old"; - if (socket.send(packet) != fr::Socket::Success) - { - //Failed to send packet - cout << "CLIENT:Seems got something wrong when sending" << endl; - return -1; - } - - cout << "CLIENT:Going to receive ..." << endl; - - - if (socket.receive(packet) != fr::Socket::Success) - { - cout << "CLIENT:seems got something wrong when receiving" << endl; - return -2; - } - - std::string str1, str2; - float age; - packet >> str1 >> age >> str2; - - cout << "CLIENT:we got:" << str1 << age << str2 << endl; - - cout << "CLIENT:round finished" << endl; - cout << endl << endl << endl << endl; - return 0; -} - - -int main() -{ - fr::TcpSocket socket; - - string server_ip = "127.0.0.1"; - string server_port = "8081"; - - if (socket.connect(server_ip, server_port) != fr::Socket::Success) - { - //Failed to connect - cout << "CLIENT:it seem that the socket can be accessed or there is no such socket at all" << endl; - socket.close_socket(); - return -1; - } - - - string op_str; - int rtn = 0; - - while (true) { - cout << "CLIENT:choose what you want to do, `c` for `continue`, `q` for `quit`:" << endl; - cin >> op_str; // count for possible mutiple char input - - if (op_str.length() > 1) { - cout << "CLIENT:Seems that you input more than one char, plese check your input" << endl; - continue; - } - - char op = op_str[0]; - switch (op) { - case 'c': - cout << "continue" << endl; - rtn = client_round(socket); - break; - case 'q': - break; - } - - if (op == 'q') - break; - if (rtn != 0) - break; - } - - socket.close_socket(); - cout << "all done, bye" << endl; -} - diff --git a/examples/tcpsocket_server.cpp b/examples/tcpsocket_server.cpp deleted file mode 100644 index d1d4e7e..0000000 --- a/examples/tcpsocket_server.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include - -using namespace std; - -int main(){ - //fr::HttpSocket client; //fr::TcpSocket for HTTP. fr::SSLSocket for HTTPS. - - fr::TcpSocket client; - - - fr::TcpListener listener; //Use an fr::SSLListener if HTTPS. - - string port = "8081"; - - //Bind to a port - if(listener.listen(port) != fr::Socket::Success) - { - cout << "LISTENER:Failed to bind to port, going to shutdown" << endl; - listener.shutdown(); - return -1; - } - - cout << "LISTENER:Listener is listening on port " << port << " ..." << endl; - - while (true) - { - cout << "LISTENER:Waiting for a new connection ..." << endl; - //Accept a new connection - if (listener.accept(client) != fr::Socket::Success) - { - cout << "LISTENER:Failed to accept client, shutdown" << endl; - break; - } - - while (true) // infinate loop for the communication - { - try - { - fr::Packet packet; - if (client.receive(packet) != fr::Socket::Success) - { - cout << "LISTENER:Failed to receive request" << endl; - } - - std::string str1, str2; - float age; - packet >> str1 >> age >> str2; - - cout << "LISTENER:We got from client:" << str1 << age << str2 << endl; - - - if (client.send(packet) != fr::Socket::Success) - { - cout << "LISTENER:Seems got something wrong when sending" << endl; - //return -2; - } - } - catch (const std::exception& e) - { - cout << "ERROR: " << e.what() << endl; - cout << "LISTENER:Seems that the client stop the connection, just destory current connection and wait for another" << endl; - //Close connection - client.close_socket(); - break; - } - } // inner while - - - }// out while - - cout << "Should not got there !!" << endl; - listener.shutdown(); - return 0; -} -