소켓을 생성하여 CSocket에 Attach하는 방법 | |||
| |||
아무것도 잘못된것이 없는것 같은데... 이 경우 다음과 같이 하면 처리가 가능하다. int CreateSocketConnection(char *host,int port) { int Socket, r; struct sockaddr_in cliAddr; struct hostent *myent; struct in_addr myen; long int *add; Socket = socket( AF_INET, SOCK_STREAM, 0); if (Socket<0) { // connection creation return 0; } else { // get ip address by host name r=0; myent = gethostbyname(host); while(*myent->h_addr_list != NULL) { add = (long int *)*myent->h_addr_list; myen.s_addr = *add; myent->h_addr_list++; r++; } // set socket connection structure memset((char *) &cliAddr, 0, sizeof(cliAddr)); cliAddr.sin_family = AF_INET; if (r) cliAddr.sin_addr.s_addr = inet_addr( inet_ntoa(myen)); else cliAddr.sin_addr.s_addr = inet_addr( host); cliAddr.sin_port = htons(port); // create connection r = connect(Socket, (struct sockaddr FAR*)&cliAddr, sizeof(cliAddr)); if (r < 0) { // connection failure return 0; } else { return Socket; } } } void CMy2007_07_16socket_testDlg::OnFetch() { int sck; sck = CreateSocketConnection( "kurapa.com", 80); if (sck) { AfxMessageBox( "Socket connection successfull"); CSocket s; if (s.Attach( sck)) { // attachment successfull AfxMessageBox( "attach 성공!"); } else { AfxMessageBox( "됀장"); closesocket( sck); } } else { AfxMessageBox( "Connection Failure"); } } Tags: Attach CSocket client socket 소켓 윈도우즈 클라이언트 | |||
| |||
| |||
Login for comment |