CJSocket::CJSocket()
{
strcpy(m_serverIp,"127.0.0.1");
m_serverPort = 5555;
}
BOOL CJSocket::VersionCheck()
{
//WinSock版本验证函数
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return FALSE;
}
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
WSACleanup( );
return FALSE; 本文来自优.文~论^文·网原文请找腾讯324.9114
}
if ((m_socket=socket(AF_INET,SOCK_DGRAM,0))==INVALID_SOCKET)
{
return FALSE; //套接字创建失败
}
return TRUE;
}
BOOL CJSocket::InitSock()
{
//套接字初始函数
m_servaddr.sin_family = AF_INET;
m_servaddr.sin_addr.s_addr = inet_addr(m_serverIp);
m_servaddr.sin_port = htons(m_serverPort);
int opt=1; //设置地址重复利用选项
int ret = setsockopt(m_socket,SOL_SOCKET,SO_REUSEADDR,(const char*)&opt,sizeof(opt)); //设置地址重复利用
if( ret == SOCKET_ERROR)
{
TRACE("Error: set socketOption failed ! Error code = %d\n",WSAGetLastError());
return FALSE;
}
return TRUE;
}
void CJSocket::SetServerIP(char *ip)
{
//套接字绑定的IP设置函数
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>