downloadsocket.h

来自「wisock应用队列思想实现单线程多任务http下载的类. 实现多文件同时下载」· C头文件 代码 · 共 56 行

H
56
字号
/*
	socket基类,所有协议类从该类继承 
*/

#pragma once

#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_ 

#include <winsock2.h> 
#include <WS2TCPIP.H> //for ipv6
#pragma comment(lib, "ws2_32.lib")

#endif
#include <TCHAR.H>
#include <stdio.h>
#include <string.h>
#include <windows.h>

#include "stateCode.h"
class CDownloadSocket
{

protected:
	SOCKET m_socket;

	TCHAR m_lpszHost[128];//static
	UINT m_port;//static

	TCHAR m_lpszUrl[1024];

public:
	CDownloadSocket(void);
	~CDownloadSocket(void);

	bool CheckDll();//检测ws2_32.lib正确性
	bool IniSocket();//初始化
	bool Connect( LPTSTR host,UINT port );//建立 网络连接

	virtual void Login()=0;

	int Send(LPTSTR buf) ;//
	int Recv(LPTSTR buf,int len) ;
	void SetUrl(LPCTSTR lpszUrl);

	virtual void SetOffset(int offset) = 0;
	virtual int SendRequest(LPTSTR buf,UINT begin =0,UINT end = 0) = 0;
	virtual int RecvData(LPTSTR buf) = 0;//得到文件数据,放在buf里
	virtual void CloseSocket()=0;
	virtual UINT GetContentLen(LPCTSTR buf) = 0;
	virtual UINT GetHeaderLen(LPCTSTR buf) = 0;
	virtual void IgnoreIpHeader(LPTSTR buf) = 0;
	virtual RESPONSECODE GetResponse(LPCTSTR buf)= 0;

};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?