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.
...全文
80 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
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();

4,387

社区成员

发帖
与我相关
我的任务
社区描述
通信技术相关讨论
社区管理员
  • 网络通信
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧