BOOL InitNet(CString m_strGXCJPath)
{
DWORD SocketMode = 0;
int nPort;
CString m_strCfgInspect;
char cIPAddr[20]="\0";
sockaddr_in addr;
int ret;
m_strCfgInspect= m_strGXCJPath + "\\DPSet.ini";
nPort = GetPrivateProfileInt("ItemDP","Port",-1,m_strCfgInspect); //端口
GetPrivateProfileString("ItemDP","IPAddr",(LPCTSTR)"",cIPAddr,20,m_strCfgInspect); //IP 地址
WSADATA data; //定义WSADATA结构体对象
WSAStartup(MAKEWORD(2,2),&data) ;
LocSocket=::socket(AF_INET,SOCK_STREAM,0);
:: WSAAsyncSelect(LocSocket,this->m_hWnd,WM_SOCK, FD_READ|FD_CONNECT);
addr.sin_family=AF_INET;
addr.sin_addr.S_un.S_addr=inet_addr(cIPAddr);
addr.sin_port=ntohs(nPort);
ret = connect(LocSocket,(sockaddr*)&addr,sizeof(addr));
if(ret) //为什么总返回-1 ???/
return TRUE;
return FALSE;
|