#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 string (*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);
|
static const int PORT = 9001;
|
static const int OCR_PORT = 9002;
|
|
sockaddr_in clientaddr;
|
SOCKET getClient(int p);
|
//Ìí¼Ó¿Í»§¶Ë
|
void addClient(int p);
|
|
static void* callbackContext;
|
static ActionCallback actionCallback;
|
|
public:
|
|
static string ADDR;
|
|
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);
|
|
string sendMsg(int, const char *);
|
|
static string sendMsg(const char*);
|
|
static string sendOcrMsg(const char*);
|
|
|
};
|