| | |
| | | #include "framework.h" |
| | | #include <atlstr.h> |
| | | using namespace std; |
| | | |
| | | #define LOCAL_SERVER_ADDR "127.0.0.1" |
| | | #define LOCAL_SERVER_PORT 9006 |
| | | |
| | | typedef bool (*ActionCallback)(string data, void* contex); |
| | | |
| | | class SocketManager |
| | | { |
| | | |
| | | |
| | | private: |
| | | list<SOCKET> sockClients; |
| | | static SOCKET socketServer; |
| | | static void runSocketServer(void* context); |
| | | static void processMsg(SOCKET client, void* context); |
| | | const int PORT = 9001; |
| | | const char* ADDR = "127.0.0.1"; |
| | | sockaddr_in clientaddr; |
| | |
| | | //添加客户端 |
| | | void addClient(int p); |
| | | |
| | | |
| | | static void* callbackContext; |
| | | static ActionCallback actionCallback; |
| | | |
| | | public: |
| | | SocketManager(); |
| | | SocketManager(ActionCallback callback,void * context); |
| | | ~SocketManager(); |
| | | |
| | | void init(); |
| | | void init(ActionCallback callback, void* contex); |
| | | |
| | | int getClientsNum(); |
| | | |
| | |
| | | void disConnect(); |
| | | int disConnect(int p); |
| | | |
| | | BOOL sendMsg(int,char *); |
| | | BOOL sendMsg(int, const char *); |
| | | |
| | | |
| | | }; |