basesocket.h
来自「a self encapsulated socket lib」· C头文件 代码 · 共 43 行
H
43 行
#pragma once
#include <Windows.h>
#include <iostream>
#include <algorithm>
#include "Data.h"
//open a file in a specified mode, returns a smart pointer pointed to the FILE struct
std::tr1::shared_ptr<FILE> getfd(std::string filename, std::string mode);
//decode a task from a string named data;
void decode_task(std::string data, Task& task);
//encode a task with a specific instruction;
std::string encode_task(std::string istrct, Task task);
//a helper function for the decoding of task
std::string getsubstr(std::string& data, int& i , int& j);
class BaseSocket
{
public:
static const int ERR = -1;
BaseSocket(void);
~BaseSocket(void);
int Receive(const SOCKET&);
static int SendBuff(SOCKET socket, const char buff[]);
static int RecvBuff(SOCKET socket, char buff[]);
protected:
int Startup();
int Cleanup();
static const int PORT = 4000; //the server side port
static const char* IP_ADDRESS; //the ip address of server
struct sockaddr_in m_serverAddr;
int AddrLen;
private:
virtual int InitSocket() = 0; //Init socket
BaseSocket(const BaseSocket&); //forbide the copy constructor
BaseSocket& operator=(const BaseSocket&); //and the assignment operator
static DWORD WINAPI RecvThread(LPVOID lpParameter);
static DWORD WINAPI SendThread(LPVOID lpParameter);
WSADATA Ws;
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?