CS144笔记
概述
课程官网:CS 144: Introduction to Computer Networking
我的实现代码:zlh123123/CS144 (github.com)
Checkpoint 0 networking warmup
lab文档:check0.pdf (cs144.github.io)
1 配置实验环境
在Ubuntu 22.04
系统中,运行指令
1 |
|
当然还有多种配置环境方式,可参考check0.pdf (cs144.github.io)
2.1 客户端手动访问网站
在Ubuntu
命令行中输入
1 |
|
得到输出如下
1 |
|
表明已经连接上 http://cs144.keithw.org/hello 。随后输入三行设置规则后按下回车
1 |
|
这里注意:telnet
连接是有时间限制的,太长时间不输入连接会自动关闭哦;在输入设置规则时,每条规则前不能有空格等字符,否则无法识别。
这三行代码的意思是:
- 该请求为
GET
请求,使用HTTP/1.1
协议,目标路径是/hello
- 目标主机是
cs144.keithw.org
Connection: close
表示在完成请求后立即关闭与服务器的连接。
成功运行后的结果如下
1 |
|
这里的Hello, CS144!
与直接打开网址 http://cs144.keithw.org/hello 的结果是一样的,这样就🆗啦。
这里还有一个Assignment,要求访问 http://cs144.keithw.org/lab0/sunetid ,这个sunetid
似乎是学号?做法和上述一致:
1 |
|
输出为
1 |
|
2.2 给自己发邮件
这个实验貌似需要斯坦福的邮箱地址才能得到效果❓这里就没有写
2.3 服务器端在干什么
首先输入指令
1 |
|
建立一个监听端口为9090的服务器,其中
-v
: 启用详细模式,会显示更多调试信息。-l
: 监听模式,告诉netcat在指定的端口上监听连接。-p 9090
: 指定监听的端口号为9090。
另外开一个终端,输入
1 |
|
使用telnet工具连接到本地主机上的端口9090。具体含义如下:
telnet
: 是一个用于远程登录的协议和工具,通过telnet可以连接远程主机的端口。localhost
: 表示本地主机,即指向本机IP地址127.0.0.1。9090
: 指定要连接的端口号为9090。
这个指令的作用是使用telnet工具连接到本地主机上的9090端口,来与在该端口上运行的服务进行通信或交互。
此时,向netcat窗口中输入任何信息,都会在telnet窗口中显示出来;反之亦然。
3 为TCP写一个可靠字节流传输程序
对于Internet而言,它只能“尽最大努力”来传输数据。然鹅这些数据可能会被丢失、被纂改、顺序错误或者发了多次,因此我们需要写一个程序来保证这个传输的“可靠的”。我们写的程序webget
用来创建 TCP stream socket
,完成上面的连接服务器和访问网页的操作。
首先下载资源文件
1 |
|
注:这里在执行cmake
指令时,可能遇到
1 |
|
在更新cmake
时,可以使用下列操作
1 |
|
这个程序有下列要求
- 我们要写的代码在
/apps/webgets.cc
中的get_URL
函数 - 要使用
TCPSocket
andAddress
这两个类 - 代码没几行
- 行间以
\r\n
进行分割
以下为编写流程
- 本文作者:Linghao Zhang
- 本文链接:http://zlh123123.github.io/2024/07/16/CS144%E7%AC%94%E8%AE%B0/index.html
- 版权声明:本博客所有文章均采用 BY-NC-SA 许可协议,转载请注明出处!