⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basesocket.h

📁 a self encapsulated socket lib
💻 H
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -