#pragma once
|
#include<WinSock2.h>
|
#include <WS2tcpip.h>
|
#pragma comment(lib,"ws2_32.lib")
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <windows.h>
|
#include <list>
|
#include <iostream>
|
#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;
|
SOCKET getClient(int p);
|
//Ìí¼Ó¿Í»§¶Ë
|
void addClient(int p);
|
|
static void* callbackContext;
|
static ActionCallback actionCallback;
|
|
public:
|
SocketManager(ActionCallback callback,void * context);
|
~SocketManager();
|
|
void init(ActionCallback callback, void* contex);
|
|
int getClientsNum();
|
|
void resetClient(int p);
|
|
//Á¬½ÓËùÓÐ
|
int Connect();
|
int Connect(int p);
|
|
//¶Ï¿ªËùÓÐ
|
void disConnect();
|
int disConnect(int p);
|
|
BOOL sendMsg(int, const char *);
|
|
static BOOL sendMsg(const char*);
|
|
|
};
|