--- /dev/null
+//////////////////////////////////////////////\r
+// Client.cpp\r
+\r
+#include <iostream>\r
+#include <string>\r
+#include "winsock2.h"\r
+#include "socket.h"\r
+\r
+using namespace std;\r
+using namespace Win32xx;\r
+\r
+\r
+class CClientSocket : public CSocket\r
+{\r
+public:\r
+ CClientSocket() {}\r
+ virtual void OnReceive()\r
+ {\r
+ // This function is called automatically when there is data to receive\r
+ char str[1024] = {0};\r
+ int i = Receive(str, 1024, 0);\r
+\r
+ cout << i << " chars received: " << str << endl;\r
+ }\r
+};\r
+\r
+int main()\r
+{\r
+ CClientSocket Client;\r
+\r
+ // Create the socket to communicate with the Server\r
+ if (!Client.Create(AF_INET, SOCK_STREAM))\r
+ {\r
+ cout << "Failed to create socket\n" ;\r
+ return 0;\r
+ }\r
+\r
+ // Connect to the server\r
+ if (SOCKET_ERROR == Client.Connect("127.0.0.1", "3000"))\r
+ {\r
+ cout << "Failed to connect to server. Was it running?\n";\r
+ return 0;\r
+ }\r
+ cout << "Connected to server.\n";\r
+ cout << "Type data to send, type quit to exit\n";\r
+\r
+ // Monitor the client socket for network events, such as data ready to receive\r
+ Client.StartEvents();\r
+\r
+ // Send data to the server\r
+ string s;\r
+ for (;;) // Infinite loop\r
+ {\r
+ getline(cin, s);\r
+ if (s == "quit") break;\r
+ int i = Client.Send(s.c_str(), (int)s.length(), 0);\r
+ cout << "Sending " << i << " characters\n";\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r