Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

¡¾C++¡¿ÊµÓÃsocket±à³Ì »ñÈ¡ÍøÒ³htmlÐÅÏ¢

 // Socket1.cpp : ¶¨Òå¿ØÖÆ̨ӦÓóÌÐòµÄÈë¿Úµã¡£
//
#include "stdafx.h"
#include<winsock.h>
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
#define WSWENS MAKEWORD(2,0)
int _tmain(int argc, _TCHAR* argv[])
{
sockaddr_in sin;
WSADATA wsadata;
//WSAStartup()µÄµ÷Ó÷½ºÍWindows Sockets DLL»¥Ïà֪ͨ¶Ô·½ËüÃÇ¿ÉÒÔÖ§³ÖµÄ×î¸ß°æ±¾,
//²¢ÇÒ»¥ÏàÈ·È϶Է½µÄ×î¸ß°æ±¾ÊǿɽÓÊܵÄ. ÔÚWSAStartup()º¯ÊýµÄÈë¿Ú,
//Windows Sockets DLL¼ì²éÁËÓ¦ÓóÌÐòËùÐèµÄ°æ±¾.Èç¹û°æ±¾¸ßÓÚDLLÖ§³ÖµÄ×îµÍ°æ±¾,
//Ôòµ÷Óóɹ¦²¢ÇÒDLLÔÚwHighVersionÖзµ»ØËüËùÖ§³ÖµÄ×î¸ß°æ±¾,
//ÔÚ wVersionÖзµ»ØËüµÄ¸ß°æ±¾ºÍwVersionRequestedÖеĽÏСÕß.
//È»ºóWindows Sockets DLL¾Í»á¼ÙÉèÓ¦ÓóÌÐò½«Ê¹ÓÃwVersion.
if(WSAStartup(WSWENS,&wsadata)!=0)

cout<<"startup failed"<<endl;

SOCKET s = socket(PF_INET,SOCK_STREAM,0);
// memset ÊǶÔÒ»¶ÎÄÚ´æ¿Õ¼äÈ«²¿ÉèÖÃΪij¸ö×Ö·û
memset(&sin,0,sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(80);
//sin.sin_addr.S_un.S_addr=inet_addr("203.208.37.99");
hostent* hptr = gethostbyname("www.google.cn");
// ½«ÓвÎÊýµÄstringÄÚÈÝcopyµ½×ó±ß²ÎÊý
memcpy(&sin.sin_addr.S_un.S_addr,hptr->h_addr,hptr->h_length);
printf("IP address:%d.%d.%d.%d\n",sin.sin_addr.S_un.S_un_b.s_b1,
sin.sin_addr.S_un.S_un_b.s_b2,
sin.sin_addr.S_un.S_un_b.s_b3,
sin.sin_addr.S_un.S_un_b.s_b4);
// ½«sockaddr_in transfer to sockaddr
if(connect(s,(sockaddr*)&sin,sizeof(sin)))
{
cout<<"connect failed"<<endl;
return 0;
}
else
{
cout<<"connect success"<<endl;
}
char buffersend[]="GET/HTTP1.1\nHOST:www.google.cn\nconnection:close\n\n";
send(s,buffersend,strlen(buffersend),0);
/*string ss;
int len = recv(s,const_cast<char*>(ss.c_str()),2000,0);*/
char bufferecv[10240];
int len=recv(s,bufferecv,10240,0);
printf("the length of page is %d\n", len);


Ïà¹ØÎĵµ£º

C/C++¶àÖÖ·½·¨»ñÈ¡Îļþ´óС

#include <iostream>
#include <io.h>
#include <sys\stat.h>
#include <afx.h>
#define _AFXDLL
using namespace std;
void main()
{
    // ´ËÎļþÔÚ¹¤³Ì´ò¿ª×´Ì¬ÏÂΪ²»¿É·ÃÎÊ
    char* f ......

[ËæÏë]C/C++³ÌÐòÔ±

       ¸Õ¸Õ¿´¹ýÕâƪ¡¶30 years of C¡·£¬»ØÏëÁËÕ⼸ÄêµÄѧϰÀú³Ì¡£
      ÔÚ´óѧÀÎÒѧϰµÄµÚÒ»ÃųÌÐòÉè¼ÆÓïÑÔÊÇC£¬µ«»¨Ê±¼ä×î¶àµÄ»¹ÊÇC++¡£´óÔ¼ÎåÄêÇ°£¬¿ªÊ¼¿Ð¡¶ C++±à³Ì˼Ïë¡·Á½¾í±¾£¬ÓÃDev-cppÔÚ»úÆ÷Á·Ï°×ÅÊéÉϵÄÒ»¸ö¸öÀý×Ó³ÌÐò£¬Ö®ºóÓÖѧϰÁËÃæÏò¶ÔÏó±à³Ì¡¢STL¡¢Ä£°å¡£Æ¾×Å ......

C/C++——С±à̸CÓïÑÔº¯ÊýÄÇЩÊÂ(20)

C³ÌÐòÊÇÓÉÒ»×é»òÊDZäÁ¿»òÊǺ¯ÊýµÄÍⲿ¶ÔÏó×é³ÉµÄ¡£ º¯ÊýÊÇÒ»¸ö×ÔÎÒ°üº¬µÄÍê³ÉÒ»¶¨Ïà¹Ø¹¦ÄܵÄÖ´ÐдúÂë¶Î¡£ÏÂÃæС±àºÍ´ó¼Ò·ÖÏíÏÂCÓïÑÔÖеĺ¯Êý¡£
 
1.     setallpalletteº¯Êý
setallpalletteº¯ÊýµÄ¹¦ÄÜÊÇ°´Ö¸¶¨·½Ê½¸Ä±äËùÓеĵ÷É«°åÑÕÉ«£¬ÆäÓ÷¨Îª£ºvoid far setallpallette(struct palette, fa ......

C/C++Êý×éÃûÓëÖ¸ÕëÇø±ðÉîÈë̽Ë÷

ÒýÑÔ
¡¡¡¡Ö¸ÕëÊÇC/C++ÓïÑÔµÄÌØÉ«£¬¶øÊý×éÃûÓëÖ¸ÕëÓÐÌ«¶àµÄÏàËÆ£¬ÉõÖÁºÜ¶àʱºò£¬Êý×éÃû¿ÉÒÔ×÷ΪָÕëʹÓá£ÓÚÊǺõ£¬ºÜ¶à³ÌÐòÉè¼ÆÕ߾ͱ»¸ãºýÍ¿ÁË¡£¶øÐí¶àµÄ´óѧÀÏʦ£¬ËûÃÇÔÚCÓïÑԵĽÌѧ¹ý³ÌÖÐÒ²´íÎóµÃ¸øѧÉú½²½â£º"Êý×éÃû¾ÍÊÇÖ¸Õë"¡£ºÜÐÒÔË£¬ÎҵĴóѧÀÏʦ¾ÍÊÇÆäÖÐÖ®Ò»¡£Ê±ÖÁ½ñÈÕ£¬ÎÒÈÕ¸´Ò»ÈյؽøÐÐ×ÅC/C++ÏîÄ¿µÄ¿ª·¢£¬¶øÉí±ß» ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ