📄 clientsocket.h
字号:
/*******************************************************************************
* (C) Copyright 2008 Giant Electronics LTD
*
* These computer program listings and specifications are the property of Giant
* Electronics LTD and shall not be reproduced or copied or used in whole or in
* part without written permission from Giant Electronics LTD .
*
* Project: IViewer
* File Name: ClientSocket.h
* Programer(s): Ben Zhan
* Created: 20080729
* Description: interface for encapsulating Wince socket APIs
* This class encapsulates the wince Socket API.
*******************************************************************************/
#if !defined(AFX_CLIENTSOCKET_H__CC4F33C1_8365_4EF2_BE01_9441DC04B93E__INCLUDED_)
#define AFX_CLIENTSOCKET_H__CC4F33C1_8365_4EF2_BE01_9441DC04B93E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <Winsock2.h>
//#pragma comment(lib, "WS2_32.LIB")
#define SOCKET_VERSION 2.2
#define S_SOCKET_OK 0X10
#define E_SOCKET_CLOSE 0X11
#define E_SOCKET_FAIL 0X12
#define E_SOCKET_NOT_READY 0x13
#define E_SOCKET_TIMEOUT 0x14
#define E_SOCKET_CANCEL 0x15
#define WM_CLIENTSOCKET WM_USER + 0x01
enum WAIT_TYPE{
WAIT_CONNECT = 0,
WAIT_SEND,
WAIT_RECV
};
class CClientSocket
{
public:
CClientSocket();
virtual ~CClientSocket();
SOCKET m_hSocket;
private:
HANDLE m_hWaitEvent;
public:
bool Attach(SOCKET inSock);
SOCKET Detach(void);
//直接调用API,阻塞套接字调用时,当服务端没数据返回,线程将阻塞
int recv(char * outBuf, int nLen);
int Receive(char * outBuf, int inLen);
int Send(const char * inData, int nLen);
bool Connect(LPCSTR lpszTarget, int iPort, HANDLE hCancelEvent=NULL);
void Disconnect(void);
int WaitForSocket(WAIT_TYPE waitType,int nSecs=20,HANDLE hCancelEvent = NULL);
void SetRecvTimeout (DWORD dwTime=10000) ; //设置接收超时
void SetSendTimeout (DWORD dwTime=10000) ; //设置发送超时
void SetConnectTimeout (DWORD dwTime=10000) ;//设置连接超时,调用了此函数,套接字变成非阻塞
void AsyncSelect (long lEvent , HWND hWnd) ; //异步选择
void SetBlock (BOOL bBlock) ; //阻塞设置,默认为阻塞
static BOOL SocketInit();
private:
DWORD m_dwConnectTimeout ;
DWORD m_dwRecvTimeout ;
DWORD m_dwSendTimeout ;
long m_lEventSelected ;
BOOL m_bBlock ;
HWND m_hWnd ;
};
#endif // !defined(AFX_CLIENTSOCKET_H__CC4F33C1_8365_4EF2_BE01_9441DC04B93E__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -