• 全部
  • 问答

How to do a net program in pure C, not in VC or others?

dot99 2002-08-25 06:00:07
I want to make a simple HTTP client program.
It can exchange information with http server.
The information can be a http header or other.
I know how to program in Borland C++ Biulder or VC but in pure C (using gcc, lcc or other).
Is there any documents I can get from internet?
Or who can send me some simple example for studying kindly?

Thanks.

sorry, I'm in the English System can't type Chinese.

dot99.
...全文
10 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
cai3995 2002-08-25
use the Socket API
回复
richard2010 2002-08-25
A reference example:


//variables.
WSADATA ws; //ws data.
SOCKET s; //socket s.
struct sockaddr_in addr; //socket address.

int iResult; //connect result.
long lResult; //startup result.

//set value.
char strSubAddr[100]; //HTTP command.
char strBuffer[500]; //receive buffer.

//Winsock startup.
lResult = WSAStartup(0x0101,&ws);

//create socket.
s = socket(AF_INET,SOCK_STREAM,0);

//set address value.
addr.sin_family = AF_INET; //standard addr family(host byte order).
addr.sin_port = htons(80); //http port(network byte order).
addr.sin_addr.s_addr = inet_addr("211.147.104.5"); //(network byte order)

//connect to the HTTP server.
iResult=connect(s,(struct sockaddr *)&addr, sizeof(addr));

//error handling.
if(SOCKET_ERROR == iResult)
{
// connect failed.
WSACleanup();
return FALSE;
}
else {
strcpy(strSubAddr, "GET /khfw/fwzn.htm\r\n"); //http request.
strcpy(fname, "c:\\download.htm"); //local file.

//send the http request.
iResult = send(s, strSubAddr,strlen(strSubAddr),0);

// download.
do {
strset(strBuffer,' '); //clear the receiving buffer.
iResult = recv(s,strBuffer,sizeof(strBuffer),0); //receive data.
LogFile(strBuffer); //transfer from memory to hardisk.
} while( iResult !=0 );
}

//clear the socket.
WSACleanup();
回复
相关推荐
发帖
通信技术
创建于2007-08-27

4037

社区成员

通信技术相关讨论
申请成为版主
帖子事件
创建了帖子
2002-08-25 06:00
社区公告
暂无公告