char szTmp[256],buf[2096];
unsigned long nAddr = inet_addr(SockSrvIP.Trim().c_str());//服务器IP
if ( nAddr == INADDR_NONE)
{
DealException("无效的IP地址","错误",MB_OK+MB_ICONERROR,true);
return;
}
::ZeroMemory(&GxtMain->wsaData,sizeof(WSAData));
WORD version = MAKEWORD(2,0);
if ( ::WSAStartup(version,&GxtMain->wsaData) !=0 )
{
DealException("Failed to initial winsock enviroment!","Gxt Error",MB_OK+MB_ICONERROR,true);
return;
}
char ComputerName[255];
gethostname(ComputerName,255);//得本计算机名
struct hostent *he = gethostbyname(ComputerName);
if ( !he )
{
DealException("Failed to get information to host!","Gxt Error",MB_OK+MB_ICONERROR,true);
::WSACleanup();
return;
}
//建立一个新的Socket
GxtMain->Socket = INVALID_SOCKET;
//UDP方式
GxtMain->Socket = socket(AF_INET,SOCK_DGRAM,0);
if ( GxtMain->Socket == INVALID_SOCKET)
{
DealException("Failed to create a new socket!","Gxt Error",MB_OK+MB_ICONERROR,true);
::WSACleanup();
return;
}
struct sockaddr_in client;
unsigned long nClient;
memcpy(&nClient,he->h_addr_list[0],sizeof(int));