Linux网络编程基础实验(17)
时间:2025-04-21
时间:2025-04-21
了解SOCKET编程,熟悉C/S模式服务器和客户端。
make tcpclient
如无错误,将会产生tcpclient可执行文件,两次运行./tcpclient,第一次给出一个错误的服务器端IP地址或端口号,观察本机错误提示信息,验证TCP为可靠连接方式;第二次给出正确的服务器IP地址和端口号,观察教师机服务端。
3、简易Web服务器
设计一个简易Web服务器程序,端口为80,该服务器程序运行后可通过浏览器访问到一个简易Web页面,页面主要信息为本人“学号+姓名”。可同学之间互相访问验证。
(1)编写代码。简易Web服务器参考程序websvr.c: /*简易Web服务器程序*/ #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <sys/types.h>
#include <netinet/in.h>
#include <sys/wait.h>
#include <sys/socket.h> #define PORT 80
#define BACKLOG 10 #define LENGTH 1024
char httpweb[]={ "HTTP/1.0 200 OK\r\n" "Date: Sun, 17 Apr 2011 2011:10:00 GMT\r\n" "Server: tinyHttp/1.0 0891141 Corporation\r\n" "Accept-Ranges: bytes\r\n" "Connection: Keep-Close\r\n"
"Content-Type: text/html\r\n"
上一篇:用友系列产品报价表
下一篇:牙龈萎缩的治疗方法是什么