///////////////////////////////////////////////////////////////////// // SocketsServer.cpp - Test driver acting as Sockets server // // ver 1.1 // // Language: Visual C++, 2005 // // Platform: Dell Dimension 9150, Windows XP Pro, SP 2.0 // // Application: Utility for CSE687 and CSE775 projects // // Author: Jim Fawcett, Syracuse University, CST 2-187 // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// /* ver 1.1 : 11 Apr 06 - eliminated static calls to SocketSystem to reflect changes that removed static calls from that class. ver 1.0 : 10 Apr 06 - first release */ #include #include "Sockets.h" #include void main() { std::cout << "\n Testing Socket Server"; std::cout << "\n =======================\n"; try { SocketSystem su; std::string host = su.getHostName(); std::cout << "\n host machine name: " << host.c_str(); std::string ip = su.getIpFromName(host); std::cout << "\n IP Address of machine: " << ip.c_str() << '\n'; std::cout << "\n receiving from connector"; std::cout << "\n --------------------------"; SocketListener listener(2048); Socket recvr = listener.waitForConnect(); std::cout << "\n remote ip is: " << recvr.getRemoteIP(); std::cout << ", remote port is: " << recvr.getRemotePort(); std::cout << "\n local ip is: " << recvr.getLocalIP(); std::cout << ", local port is: " << recvr.getLocalPort() << '\n'; recvr.setTerminator(""); while(true) { std::string msg = recvr.recv(); std::cout << "\n received \"" << msg; if(msg == "quit") break; } std::cout << "\n"; // demonstrating full duplex operation std::cout << "\n sending back to connector"; std::cout << "\n ---------------------------"; recvr.send("sending message backquit"); std::cout << "\n sent messages\n\n"; } catch(std::exception& e) { std::cout << "\n " << e.what() << "\n\n"; } }