• 欢迎光临~

实验四 Web服务器2

开发技术 开发技术 2022-11-30 次浏览
基于华为鲲鹏云服务器CentOS中(或Ubuntu),使用Linux Socket实现:
1. Web服务器的客户端服务器,提交程序运行截图
2. 实现GET即可,请求,响应要符合HTTP协议规范
3. 服务器部署到华为云服务器,浏览器用本机的
4. 把服务器部署到试验箱。(加分项)

参考代码:

实验四 Web服务器2

copy.c:

/* copy.c:
 *
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <stdio.h>

static char copybuf[16384];

extern int TIMEOUT;

int copy(FILE *read_f, FILE *write_f)
{
  int n;
  int wrote;
  alarm(TIMEOUT);
  while (n = fread(copybuf,1,sizeof(copybuf),read_f)) {
    alarm(TIMEOUT);
    wrote = fwrite(copybuf,n,1,write_f);
    alarm(TIMEOUT);
    if (wrote < 1)
    	return -1;
  }
  alarm(0);
  return 0;
}

实验四 Web服务器2

在httpd.c文件中增加声明#define HTTPD_DOCUMENT_ROOT "."

进行编译gcc *.c -o webserver -lpthread

实验四 Web服务器2

查看IP地址:

实验四 Web服务器2

访问浏览器:输入IP192.168.87.137,可以在本机浏览器中查看

实验四 Web服务器2

发现虚拟机可以响应

实验四 Web服务器2

程序员灯塔
转载请注明原文链接:实验四 Web服务器2
喜欢 (0)
违法和不良信息举报电话:022-22558618 举报邮箱:dljd@tidljd.com