¥µ¡¼¥Ð¥×¥í¥°¥é¥à¤È¥¯¥é¥¤¥¢¥ó¥È¥×¥í¥°¥é¥à¡¢¥»¥Ã¥È¤ÇÆ°¤¤Þ¤¹ ¥µ¡¼¥Ð¥×¥í¥°¥é¥à¤Î¤Û¤¦¤ÏC/C++¥½¥±¥Ã¥È¥×¥í¥°¥é¥ß¥ó¥°Âè°ì²ó¤ò¤´Í÷¤¯¤À¤µ¤¤ ÂèÆó²ó¤Ï¥¯¥é¥¤¥¢¥ó¥È¥×¥í¥°¥é¥à¤ÎÀâÌÀ¤Ë¤Ê¤ê¤Þ¤¹ ------- ¤Þ¤º¡¢¥¯¥é¥¤¥¢¥ó¥È¥×¥í¥°¥é¥à¤Î¼ê½ç¤ò¼¨¤·¤Þ¤¹ ¡WSAStartup WinSock¥é¥¤¥Ö¥é¥ê½àÈ÷ ¢socket ¥½¥±¥Ã¥ÈºîÀ® £connect ¥µ¡¼¥Ð¤ËÀܳ ¤recv,send ¥Ç¡¼¥¿Á÷¼õ¿®¡Ê·«¤êÊÖ¤·¡Ë ¥closesocket ¥½¥±¥Ã¥È¤òÊĤ¸¤ë ¦WSACleanup WinSock¥é¥¤¥Ö¥é¥ê¸å½èÍý ¡¡Á¢¡¢¤¡Á¦¤Ï¥µ¡¼¥Ð¦¤ÈƱ¤¸¤Ç¤¹ ¼ç¤Ë¼ê½ç£¤ò¸«¤Æ¤ß¤Þ¤·¤ç¤¦ ¼ÂÁõ¤Ïclient.cpp¤Ë½ñ¤«¤ì¤Æ¤¤¤Þ¤¹ -------- ¢¡¢£¤Ç¤¹¡ÊConnect¥á¥½¥Ã¥É¡Ë // Àܳ bool CClient::Connect(const char* IP,u_short PORT) { // sockaddr_in ¹½Â¤ÂΤΥ»¥Ã¥È struct sockaddr_in dstAddr; memset(&dstAddr, 0, sizeof(dstAddr)); dstAddr.sin_port = htons(PORT); dstAddr.sin_family = AF_INET; dstAddr.sin_addr.s_addr = inet_addr(IP); // ¥½¥±¥Ã¥È¤ÎÀ¸À® m_DstSocket = socket(AF_INET, SOCK_STREAM, 0); // Àܳ if(connect(m_DstSocket, (struct sockaddr *) &dstAddr, sizeof(dstAddr)) == SOCKET_ERROR){ return false; } // ¥½¥±¥Ã¥È¤òÈóƱ´ü¥â¡¼¥É¤Ë¤¹¤ë u_long val=1; ioctlsocket(m_DstSocket, FIONBIO, &val); return true; } ¤Þ¤ºsockaddr_in¹½Â¤ÂΤòºî¤ê¤Þ¤¹ ¤³¤ì¤Ë¥µ¡¼¥Ð¤Î¥Ý¡¼¥ÈÈÖ¹æ¤ÈIP¥¢¥É¥ì¥¹¤ò»ØÄꤷ¤Þ¤¹¡£ dstAddr.sin_port¥á¥ó¥Ð¤Ë¤Ï¥Ý¡¼¥ÈÈÖ¹æ¤ò»ØÄꤷ¤Þ¤¹ dstAddr.sin_port = htons(PORT); ¤³¤Î¤È¤PORT°ú¿ô¤ËÆþ¤ë¥Ý¡¼¥ÈÈÖ¹æ¤Ï¥µ¡¼¥Ð¦¤Î¥Ý¡¼¥ÈÈÖ¹æ¤È¹ç¤ï¤»¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó dstAddr.sin_addr.s_addr ¤Ë¤Ï¥µ¡¼¥Ð¡¼Â¦¤ÎIP¥¢¥É¥ì¥¹¤ò»ØÄꤷ¤Þ¤¹ dstAddr.sin_addr.s_addr = inet_addr(IP); IP°ú¿ô¤Ë¤ÏIP¥¢¥É¥ì¥¹¤Îʸ»úÎó¤ò»ØÄꤷ¤Þ¤¹ ¥µ¡¼¥Ð¡¼¥×¥í¥°¥é¥à¤È¥¯¥é¥¤¥¢¥ó¥È¥×¥í¥°¥é¥à¤òƱ¤¸¥³¥ó¥Ô¥å¡¼¥¿¾å¤Çµ¯Æ°¤µ¤»¤ë¾ì¹ç¤Ï 127.0.0.1¤È¤¤¤¦¥Æ¥¹¥ÈÍÑIP¥¢¥É¥ì¥¹¤ò»ØÄꤷ¤Þ¤¹ ¼ÂºÝ¤ËÊ̤Υ³¥ó¥Ô¥å¡¼¥¿Æ±»Î¤ÇÀܳ¤¹¤ë¾ì¹ç¤Ï¥µ¡¼¥Ð¡¼Â¦¤ÎIP¥¢¥É¥ì¥¹¤ò»ØÄꤹ¤ëɬÍפ¬¤¢¤ê¤Þ¤¹ IP¥¢¥É¥ì¥¹¤Ï¥µ¡¼¥Ð¦¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤éipconfig¥³¥Þ¥ó¥É¤Ç³Îǧ¤Ç¤¤Þ¤¹ ¢¤Çsocket´Ø¿ô¤Ç¤Î¥½¥±¥Ã¥È¤ÎºîÀ®ÊýË¡¤Ï¥µ¡¼¥Ð¦¤ÈƱ¤¸¤Ç¤¹ £¤ÇºîÀ®¤·¤¿¥½¥±¥Ã¥È¤ÈÀè¤Û¤É¤Îsockaddr_in¹½Â¤ÂΤò»ØÄꤷ¡¢¥µ¡¼¥Ð¡¼¤ËÀܳ¤·¤Þ¤¹ ¤³¤Î¤È¤¡¢¥µ¡¼¥Ð¦¤¬accept´Ø¿ô¤ò¸Æ¤Ó½Ð¤·¤Æ¤¤¤Ê¤±¤ì¤ÐÀܳ¤Ë¼ºÇÔ¤·¤Þ¤¹ Àܳ¤ËÀ®¸ù¤·¤¿¤éÈóƱ´ü¥½¥±¥Ã¥È²½¤·¤Þ¤¹ u_long val=1; ioctlsocket(m_DstSocket, FIONBIO, &val); ÈóƱ´ü²½¤·¤¿¥½¥±¥Ã¥È¤ò¥Ç¡¼¥¿¤ÎÁ÷¼õ¿®¤Ë»È¤¤¤Þ¤¹ ----------- #vote(¡Ê¡°¦Ø¡°¡Ë¤Ç¤¤¿¡¼[59],¡£¡Ê`¦Ø¡#¡Ë¡£¤Ç¤¤Í¡¼[63]) |¡Ê¡°¦Ø¡°¡Ë¤Ç¤¤¿¡¼|59| |¡£¡Ê`¦Ø¡#¡Ë¡£¤Ç¤¤Í¡¼|63|