socket基本
fd_set用法:
http://blog.sina.com.cn/s/blog_5c8d13830100erzs.htm
socket连接:
1 lpszHost="127.0.0.1" 2 nPort = 9200 3 m_Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 4 5 if (m_Socket == SOCKET_ERROR) 6 { 7 return false; 8 } 9 10 // 构造sockaddr_in结构 11 sockaddr_in ClientAddr; 12 ClientAddr.sin_family = AF_INET; 13 ClientAddr.sin_port = htons(nPort); 14 hostent* pHostent = gethostbyname((char*)lpszHost); 15 ClientAddr.sin_addr = *((struct in_addr *)pHostent->h_addr); 16 17 if (connect(m_Socket, (SOCKADDR *)&ClientAddr, sizeof(ClientAddr)) == SOCKET_ERROR) 18 { 19 return false; 20 } 21 m_bIsRunning = true; 22 m_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WorkThread, (LPVOID)this, 0, 0);