導航:首頁 > 編程語言 > c語言伺服器編程

c語言伺服器編程

發布時間:2023-06-02 08:54:51

『壹』 如何用c語言實現http伺服器

去看一下《Advanced linux Programming》這本書吧,第11章講的就是怎麼用C語言實現一Http伺服器。 這里有下載地址(英文的): http://www.advancedlinuxprogramming.com/alp-folder 英文看起來不順的話可以上網找找有沒有中文版的這本書,應該叫Linux高級編程吧~~~參考資料: http://www.advancedlinuxprogramming.com/alp-folder

『貳』 如何用C語言開發一個通用web伺服器

用C語言開發WEB,可以用C++BUILDER6,稱ISAPI,一般人可能做不起來,有點麻煩;
唯一是速度很快,別人看不到源碼,掌握了編程套路,也可以開發應用;
缺點:
1。不是解釋性語言,做的WEB調試非常麻煩;現在做WEB開發的,用C#、JAVA較多;都是解釋性的語言;
2。因為是.DLL的二進制代碼,一般商業網站不給予運行的環境,因為網站伺服器會被你可能搞癱,安全性得不到保障;所以,你得自備網頁伺服器;
3。得不到技術支持,因為沒幾個人會這種開發;

『叄』 用C語言進行web後端編程有什麼不妥

沒有什麼問題,之前有很多CGI都是用C來寫的。
但是現在很少有人用C直接寫CGI了,因為有更好用的PHP、PERL、PYTHON

『肆』 設計一個linux c語言,Http協議的伺服器,用socket收發消息,簡單點,求代碼and注釋。

OK
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <string.h>

int main(int argc,char *argv[])
{
int sockfd,new_socket;
int sock_value;
char buf[] = "hello! China!I Love You\n";

struct sockaddr_in client_;
struct sockaddr_in server_;

int SIZE = sizeof(struct sockaddr_in);

if(argc != 2){
fprintf(stderr,"The two number!\n");
exit(1);
}

if((sock_value = atoi(argv[1])) < 0){
fprintf(stderr,"socket error!\n");
exit(1);
}

if((sockfd = socket(PF_INET,SOCK_STREAM, 0)) == -1){
perror("socket");
exit(1);
}

bzero(&server_,SIZE);

server_.sin_family = PF_INET;
server_.sin_port = htons(sock_value);
server_.sin_addr.s_addr = INADDR_ANY;

if(bind(sockfd,(struct sockaddr *)(&server_),SIZE) == -1){
perror("bind");
exit(1);
}

if(listen(sockfd, 12) == -1){
perror("listen");
exit(1);
}

printf("Waiting ... ...\n");

while(1){
if((new_socket = accept(sockfd,(struct sockaddr *)(&client_),&SIZE)) == -1){
perror("accept");
exit(1);
}

printf("The client IP is %s\n",inet_ntoa(client_.sin_addr));
printf("The socket is %d\n",ntohs(client_.sin_port));

if(write(new_socket,buf,strlen(buf)) == -1){
perror("write");
exit(1);
}

int my;
char mybuf[1024];

if((my = read(new_socket, mybuf,1024)) == -1){
perror("read");
exit(1);
}

mybuf[my] = '\0';
printf("#++++#++++#:%s\n",mybuf);

close(new_socket);

}

close(sockfd);

return 0;
}

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>

int main(int argc,char *argv[])
{
int sockfd;
int sock_value;
char buf[1024];
char mybuf[] = "Linux\n";
int read_count;

struct sockaddr_in client_;
struct sockaddr_in server_;

int SIZE = sizeof(struct sockaddr_in);

if(argc != 3){
fprintf(stderr,"The two number!\n");
exit(1);
}

if((sock_value = atoi(argv[2])) < 0){
fprintf(stderr,"socket error!\n");
exit(1);
}

if((sockfd = socket(PF_INET,SOCK_STREAM, 0)) == -1){
perror("socket");
exit(1);
}

bzero(&client_,SIZE);
bzero(&server_,SIZE);

client_.sin_family = PF_INET;
client_.sin_port = htons(52252);
client_.sin_addr.s_addr = INADDR_ANY;

server_.sin_family = PF_INET;
server_.sin_port = htons(sock_value);
server_.sin_addr.s_addr = inet_addr(argv[1]);

if(connect(sockfd,(struct sockaddr *)(&server_),SIZE) == -1){
perror("connect");
exit(1);
}

if((read_count = read(sockfd,buf,1024)) == -1){
perror("read");
exit(1);
}

buf[read_count] = '\0';
printf("#----#----#:%s\n",buf);

if(write(sockfd, mybuf,6) == -1){
perror("write");
exit(1);
}

close(sockfd);

exit(0);

return 0;
}

『伍』 c語言怎麼開發伺服器

C語言開發談鉛唯伺服器可以說是一件非常困難和辛苦的事情。首先你需要對網路編程非常熟悉,因為伺服器需要通過網路進行訪問,它必須架構在網路協議上,然後你需要對網含培絡協議和相關激信的程序設計介面非常了解,比如socket編程、http協議及其編程介面等,然後你還要使用多線程,因為伺服器不可避免地要同時接受多個訪問請求。綜上,用C語言開發伺服器需要以上技術。


閱讀全文

與c語言伺服器編程相關的資料

熱點內容
在線影視 不卡 瀏覽:168
老男孩韓國完整版百度網盤 瀏覽:485
用箱子運水怪結果被放出來了電影 瀏覽:519
徐錦江空中飛人片名 瀏覽:164
手機免費在線看福利電影 瀏覽:457
羅麗星克萊爾經典 瀏覽:342
台灣紅羊有哪些經典電影 瀏覽:568
免下載你懂的 瀏覽:975
新建文件夾1女演員三位 瀏覽:740
不用下載就能看的視頻網站 瀏覽:330
我一個神偷硬生生把國家偷成強國 瀏覽:600
樣子是五歲小男孩和郭富城演的 瀏覽:460
韓國演員也美娜 瀏覽:898
陸離是哪部小說的主角 瀏覽:49
華娛開局佟麗婭 瀏覽:17
男男生子小說現代攻姓章 瀏覽:541
永旺星星影院影訊 瀏覽:328
李彩潭巔峰之作 瀏覽:86
彎村紅羊電影 瀏覽:157
我和我的家教老師韓國 瀏覽:102