Rust vs Go:常用语法对比(十一)

alt

题目来自 Rust Vs Go: Which Language Is Better For Developing High-Performance Applications?[1]


202. Sum of squares

Calculate the sum of squares s of data, an array of floating point values.

计算平方和

package main

import (
 "math"
)

func main() {
 data := []float64{0.060.82-0.01-0.34-0.55}
 var s float64
 for _, d := range data {
  s += math.Pow(d, 2)
 }
 println(s)
}

+1.094200e+000


fn main() {
    let data: Vec<f32> = vec![2.03.54.0];

    let s = data.iter().map(|x| x.powi(2)).sum::<f32>();

    println!("{}", s);
}

32.25


205. Get an environment variable

Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".

获取环境变量

package main

import (
 "fmt"
 "os"
)

func main() {
 foo, ok := os.LookupEnv("FOO")
 if !ok {
  foo = "none"
 }

 fmt.Println(foo)
}

none

or

package main

import (
 "fmt"
 "os"
)

func main() {
 foo := os.Getenv("FOO")
 if foo == "" {
  foo = "none"
 }

 fmt.Println(foo)
}

none


use std::env;

fn main() {
    let foo;
    match env::var("FOO") {
        Ok(val) => foo = val,
        Err(_e) => foo = "none".to_string(),
    }
    println!("{}", foo);
    
    let user;
    match env::var("USER") {
        Ok(val) => user = val,
        Err(_e) => user = "none".to_string(),
    }
    println!("{}", user);
}

none
playground

or

use std::env;

fn main() {
    let foo = env::var("FOO").unwrap_or("none".to_string());
    println!("{}", foo);

    let user = env::var("USER").unwrap_or("none".to_string());
    println!("{}", user);
}

none
playground

or

use std::env;

fn main() {
    let foo = match env::var("FOO") {
        Ok(val) => val,
        Err(_e) => "none".to_string(),
    };
    println!("{}", foo);

    let user = match env::var("USER") {
        Ok(val) => val,
        Err(_e) => "none".to_string(),
    };
    println!("{}", user);
}

none
playground

or

use std::env;
if let Ok(tnt_root) = env::var("TNT_ROOT") {
     //
}

206. Switch statement with strings

Execute different procedures foo, bar, baz and barfl if the string str contains the name of the respective procedure. Do it in a way natural to the language.

switch语句

package main

import (
 "fmt"
)

func main() {
 str := "baz"

 switch str {
 case "foo":
  foo()
 case "bar":
  bar()
 case "baz":
  baz()
 case "barfl":
  barfl()
 }
}

func foo() {
 fmt.Println("Called foo")
}

func bar() {
 fmt.Println("Called bar")
}

func baz() {
 fmt.Println("Called baz")
}

func barfl() {
 fmt.Println("Called barfl")
}

Called baz


fn main() {
    fn foo() {}
    fn bar() {}
    fn baz() {}
    fn barfl() {}
    let str_ = "x";
    match str_ {
        "foo" => foo(),
        "bar" => bar(),
        "baz" => baz(),
        "barfl" => barfl(),
        _ => {}
    }
}

207. Allocate a list that is automatically deallocated

Allocate a list a containing n elements (n assumed to be too large for a stack) that is automatically deallocated when the program exits the scope it is declared in.

分配一个自动解除分配的列表

package main

import (
 "fmt"
)

type T byte

func main() {
 n := 10_000_000
 a := make([]T, n)
 fmt.Println(len(a))
}

Elements have type T. a is garbage-collected after the program exits its scope, unless we let it "escape" by taking its reference. The runtime decides if a lives in the stack on in the heap.

10000000


let a = vec![0; n];

Heap allocations are deallocated when the variable goes out of scope.


208. Formula with arrays

Given the arrays a,b,c,d of equal length and the scalar e, calculate a = e*(a+b*c+cos(d)). Store the results in a.

对数组元素进行运算

package main

import (
 "fmt"
 "math"
)

func applyFormula(a, b, c, d []float64, e float64) {
 for i, v := range a {
  a[i] = e * (v + b[i] + c[i] + math.Cos(d[i]))
 }
}

func main() {
 a := []float64{1234}
 b := []float64{5.56.67.78.8}
 c := []float64{9101112}
 d := []float64{13141516}
 e := 42.0

 fmt.Println("a is    ", a)
 applyFormula(a, b, c, d, e)
 fmt.Println("a is now", a)
}

a is     [1 2 3 4]
a is now [689.1127648209083 786.9429631647291 879.4931076599294 1001.3783018264178]


fn main() {
    let mut a: [f325] = [5., 2., 8., 9., 0.5]; // we want it to be mutable
    let b: [f325] = [7., 9., 8., 0.9650.98]; 
    let c: [f325] = [0., 0.8789456., 123456., 0.0003]; 
    let d: [f325] = [332., 0.18., 9874., 0.3]; 

    const e: f32 = 85.;

    for i in 0..a.len() {
        a[i] = e * (a[i] + b[i] * c[i] + d[i].cos());
    }

    println!("{:?}", a); //Don't have any idea about the output
}

[470.29297, 866.57544, 536830750.0, 10127158.0, 123.7286]


209. Type with automatic deep deallocation

Declare a type t which contains a string s and an integer array n with variable size, and allocate a variable v of type t. Allocate v.s and v.n and set them to the values "Hello, world!" for s and [1,4,9,16,25], respectively. Deallocate v, automatically deallocating v.s and v.n (no memory leaks).

自动深度解除分配的类型

package main

func main() {
 f()
}

func f() {
 type t struct {
  s string
  n []int
 }

 v := t{
  s: "Hello, world!",
  n: []int{1491625},
 }

 // Pretend to use v (otherwise this is a compile error)
 _ = v

 // When f exits, v and all its fields are garbage-collected, recursively
}

After v goes out of scope, v and all its fields will be garbage-collected, recursively


struct T {
 s: String,
 n: Vec<usize>,
}

fn main() {
 let v = T {
  s: "Hello, world!".into(),
  n: vec![1,4,9,16,25]
 };
}

When a variable goes out of scope, all member variables are deallocated recursively.


211. Create folder

Create the folder at path on the filesystem

创建文件夹

package main

import (
 "fmt"
 "os"
)

func main() {
 path := "foo"
 _, err := os.Stat(path)
 b := !os.IsNotExist(err)
 fmt.Println(path, "exists:", b)

 err = os.Mkdir(path, os.ModeDir)
 if err != nil {
  panic(err)
 }

 info, err2 := os.Stat(path)
 b = !os.IsNotExist(err2)
 fmt.Println(path, "exists:", b)
 fmt.Println(path, "is a directory:", info.IsDir())
}

foo exists: false
foo exists: true
foo is a directory: true

or

package main

import (
 "fmt"
 "os"
)

func main() {
 path := "foo/bar"
 _, err := os.Stat(path)
 b := !os.IsNotExist(err)
 fmt.Println(path, "exists:", b)

 err = os.Mkdir(path, os.ModeDir)
 if err != nil {
  fmt.Println("Could not create", path, "with os.Mkdir")
 }

 info, err2 := os.Stat(path)
 b = !os.IsNotExist(err2)
 fmt.Println(path, "exists:", b)

 err = os.MkdirAll(path, os.ModeDir)
 if err != nil {
  fmt.Println("Could not create", path, "with os.MkdirAll")
 }

 info, err2 = os.Stat(path)
 b = !os.IsNotExist(err2)
 fmt.Println(path, "exists:", b)
 fmt.Println(path, "is a directory:", info.IsDir())
}
foo/bar exists: false
Could not create foo/bar with os.Mkdir
foo/bar exists: false
foo/bar exists: true
foo/bar is a directory: true

use std::fs;
use std::path::Path;

fn main() {
    let path = "/tmp/goofy";
    let b: bool = Path::new(path).is_dir();
    println!("{} exists: {}", path, b);

    let r = fs::create_dir(path);
    match r {
        Err(e) => {
            println!("error creating {}: {}", path, e);
            std::process::exit(1);
        }
        Ok(_) => println!("created {}: OK", path),
    }

    let b: bool = Path::new(path).is_dir();
    println!("{} exists: {}", path, b);
}

/tmp/goofy exists: false
created /tmp/goofy: OK
/tmp/goofy exists: true

or

use std::fs;
use std::path::Path;

fn main() {
    let path = "/tmp/friends/goofy";
    let b: bool = Path::new(path).is_dir();
    println!("{} exists: {}", path, b);

    // fs::create_dir can't create parent folders
    let r = fs::create_dir(path);
    match r {
        Err(e) => println!("error creating {}: {}", path, e),
        Ok(_) => println!("created {}: OK", path),
    }

    let b: bool = Path::new(path).is_dir();
    println!("{} exists: {}", path, b);

    // fs::create_dir_all does create parent folders
    let r = fs::create_dir_all(path);
    match r {
        Err(e) => println!("error creating {}: {}", path, e),
        Ok(_) => println!("created {}: OK", path),
    }

    let b: bool = Path::new(path).is_dir();
    println!("{} exists: {}", path, b);
}
/tmp/friends/goofy exists: false
error creating /tmp/friends/goofy: No such file or directory (os error 2)
/tmp/friends/goofy exists: false
created /tmp/friends/goofy: OK
/tmp/friends/goofy exists: true

212. Check if folder exists

Set boolean b to true if path exists on the filesystem and is a directory; false otherwise.

检查文件夹是否存在

package main

import (
 "fmt"
 "os"
)

func main() {
 path := "foo"
 info, err := os.Stat(path)
 b := !os.IsNotExist(err) && info.IsDir()
 fmt.Println(path, "is a directory:", b)

 err = os.Mkdir(path, os.ModeDir)
 if err != nil {
  panic(err)
 }

 info, err = os.Stat(path)
 b = !os.IsNotExist(err) && info.IsDir()
 fmt.Println(path, "is a directory:", b)
}

foo is a directory: false
foo is a directory: true

use std::path::Path;

fn main() {
    let path = "/etc";
    let b: bool = Path::new(path).is_dir();
    println!("{}: {}", path, b);

    let path = "/goofy";
    let b: bool = Path::new(path).is_dir();
    println!("{}: {}", path, b);
}

/etc: true
/goofy: false

215. Pad string on the left

Prepend extra character c at the beginning of string s to make sure its length is at least m. The length is the number of characters, not the number of bytes.

左侧补齐字符串

package main

import (
 "fmt"
 "strings"
 "unicode/utf8"
)

func main() {
 m := 3
 c := "-"
 for _, s := range []string{
  "",
  "a",
  "ab",
  "abc",
  "abcd",
  "é",
 } {
  if n := utf8.RuneCountInString(s); n < m {
   s = strings.Repeat(c, m-n) + s
  }
  fmt.Println(s)
 }
}

---
--a
-ab
abc
abcd
--é

use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
if let Some(columns_short) = m.checked_sub(s.width()) {
    let padding_width = c
        .width()
        .filter(|n| *n > 0)
        .expect("padding character should be visible");
    // Saturate the columns_short
    let padding_needed = columns_short + padding_width - 1 / padding_width;
    let mut t = String::with_capacity(s.len() + padding_needed);
    t.extend((0..padding_needed).map(|_| c)
    t.push_str(&s);
    s = t;
}

*This uses the Unicode display width to determine the padding needed. This will be appropriate for most uses of monospaced text.

It assumes that m won't combine with other characters to form a grapheme.*


217. Create a Zip archive

Create a zip-file with filename name and add the files listed in list to that zip-file.

创建压缩文件

package main

import (
 "archive/zip"
 "bytes"
 "io"
 "io/ioutil"
 "log"
 "os"
)

func main() {
 list := []string{
  "readme.txt",
  "gopher.txt",
  "todo.txt",
 }
 name := "archive.zip"

 err := makeZip(list, name)
 if err != nil {
  log.Fatal(err)
 }
}

func makeZip(list []string, name string) error {
 // Create a buffer to write our archive to.
 buf := new(bytes.Buffer)

 // Create a new zip archive.
 w := zip.NewWriter(buf)

 // Add some files to the archive.
 for _, filename := range list {
  // Open file for reading
  input, err := os.Open(filename)
  if err != nil {
   return err
  }
  // Create ZIP entry for writing
  output, err := w.Create(filename)
  if err != nil {
   return err
  }

  _, err = io.Copy(output, input)
  if err != nil {
   return err
  }
 }

 // Make sure to check the error on Close.
 err := w.Close()
 if err != nil {
  return err
 }

 N := buf.Len()
 err = ioutil.WriteFile(name, buf.Bytes(), 0777)
 if err != nil {
  return err
 }
 log.Println("Written a ZIP file of", N, "bytes")

 return nil
}

func init() {
 // Create some files in the filesystem.
 var files = []struct {
  Name, Body string
 }{
  {"readme.txt""This archive contains some text files."},
  {"gopher.txt""Gopher names:\nGeorge\nGeoffrey\nGonzo"},
  {"todo.txt""Get animal handling licence.\nWrite more examples."},
 }
 for _, file := range files {
  err := ioutil.WriteFile(file.Name, []byte(file.Body), 0777)
  if err != nil {
   log.Fatal(err)
  }
 }
}

list contains filenames of files existing in the filesystem. In this example, the zip data is buffered in memory before writing to the filesystem.

2009/11/10 23:00:00 Written a ZIP file of 492 bytes


use zip::write::FileOptions;
let path = std::path::Path::new(_name);
let file = std::fs::File::create(&path).unwrap();
let mut zip = zip::ZipWriter::new(file); zip.start_file("readme.txt", FileOptions::default())?;                                                          
zip.write_all(b"Hello, World!\n")?;
zip.finish()?;

or

use zip::write::FileOptions;
fn zip(_name: &str, _list: Vec<&str>) -> zip::result::ZipResult<()>
{
    let path = std::path::Path::new(_name);
    let file = std::fs::File::create(&path).unwrap();
    let mut zip = zip::ZipWriter::new(file);
    for i in _list.iter() {
        zip.start_file(i as &str, FileOptions::default())?;
    }
    zip.finish()?;
    Ok(())
}

218. List intersection

Create list c containing all unique elements that are contained in both lists a and b. c should not contain any duplicates, even if a and b do. The order of c doesn't matter.

列表的交集

package main

import (
 "fmt"
)

type T int

func main() {
 a := []T{45678910}
 b := []T{13957977}

 // Convert to sets
 seta := make(map[T]boollen(a))
 for _, x := range a {
  seta[x] = true
 }
 setb := make(map[T]boollen(a))
 for _, y := range b {
  setb[y] = true
 }

 // Iterate in one pass
 var c []T
 for x := range seta {
  if setb[x] {
   c = append(c, x)
  }
 }

 fmt.Println(c)
}

[5 7 9]


use std::collections::HashSet;

fn main() {
    let a = vec![1234];
    let b = vec![246822];

    let unique_a = a.iter().collect::<HashSet<_>>();
    let unique_b = b.iter().collect::<HashSet<_>>();
    let c = unique_a.intersection(&unique_b).collect::<Vec<_>>();

    println!("c: {:?}", c);
}

c: [2, 4]

or

use std::collections::HashSet;

fn main() {
    let a = vec![1234];
    let b = vec![246822];

    let set_a: HashSet<_> = a.into_iter().collect();
    let set_b: HashSet<_> = b.into_iter().collect();
    let c = set_a.intersection(&set_b);

    println!("c: {:?}", c);
}

c: [2, 4]


219. Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.
Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

用单个空格替换多个空格

package main

import (
 "fmt"
 "regexp"
)

// regexp created only once, and then reused
var whitespaces = regexp.MustCompile(`\s+`)

func main() {
 s := `
 one   two
    three
 `


 t := whitespaces.ReplaceAllString(s, " ")

 fmt.Printf("t=%q", t)
}

t=" one two three "


use regex::Regex;

fn main() {
    let s = "
 one   two
    three
 "
;
    let re = Regex::new(r"\s+").unwrap();
    let t = re.replace_all(s, " ");
    println!("{}", t);
}

one two three


220. Create a tuple value

Create t consisting of 3 values having different types.
Explain if the elements of t are strongly typed or not.

创建元组值a

t := []interface{}{
 2.5,
 "hello",
 make(chan int),
}

A slice of empty interface may hold any values (not strongly typed).


fn main() {
    let mut t = (2.5"hello", -1);
    
    t.2 -= 4;
    println!("{:?}", t);
}

(2.5, "hello", -5)


参考资料

[1]

Rust Vs Go: Which Language Is Better For Developing High-Performance Applications?: https://analyticsindiamag.com/rust-vs-go-which-language-is-better-for-developing-high-performance-applications/

本文由 mdnice 多平台发布

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/9250.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

OpenCV 4.0+Python机器学习与计算机视觉实战

&#x1f482; 个人网站:【办公神器】【游戏大全】【神级源码资源网】&#x1f91f; 前端学习课程&#xff1a;&#x1f449;【28个案例趣学前端】【400个JS面试题】&#x1f485; 寻找学习交流、摸鱼划水的小伙伴&#xff0c;请点击【摸鱼学习交流群】 目录 前言第一部分&…

TypeScript入门学习汇总

1.快速入门 1.1 简介 TypeScript 是 JavaScript 的一个超集&#xff0c;支持 ECMAScript 6 标准。 TypeScript 由微软开发的自由和开源的编程语言。 TypeScript 设计目标是开发大型应用&#xff0c;它可以编译成纯 JavaScript&#xff0c;编译出来的 JavaScript 可以运行在…

HTTP超本文传输协议

HTTP超本文传输协议 HTTP简介HTTP请求与响应HTTP请求请求行请求头空行请求体 HTTP响应响应行响应头空行响应体 HTTP请求方法GET和POST之间的区别HTTP为什么是无状态的cookie原理session 原理cookie 和 session 的区别cookie如何设置cookie被禁止后如何使用session HTTP简介 HT…

论文阅读与管理方法论

文章目录 为什么读论文论文类型综述论文专题论文 论文质量角度关于如何找论文的小Tips如何整理论文读论文的困境如何读论文不同人群阅读差异读论文三部曲&#xff1a;泛读、精读、总结泛读&#xff1a;快速浏览&#xff0c;把握概要。泛读目标及效果自测 精读&#xff1a;选出精…

MS1826B HDMI 1进4出 视频拼接芯片

MS1826B 是一款多功能视频处理器&#xff0c;包含 4 路独立 HDMI 音视频输出通道、1 路 HDMI 音视 频输入通道以及 1 路独立可配置为输入或者输出的 SPDIF、I2S 音频信号。支持 4 个独立的字库定 制型 OSD&#xff1b;可处理隔行和逐行视频或者图形输入信号&#xff1b;有四路独…

-jar和 javaagent命令冲突吗?

当使用 -jar 命令运行 Java 应用程序时&#xff0c;Java 虚拟机 (JVM) 会忽略任何设置的 -javaagent 命令。这是因为 -jar 命令会覆盖其他命令行选项&#xff0c;包括 -javaagent。 这是因为 -jar 命令是用于运行打包为 JAR 文件的 Java 应用程序的快捷方式。它会忽略其他命令…

(原创)Flutter与Native通信的方式:MethodChannel

前言 随着Flutter混合开发的项目越来越多&#xff0c;我们也有了实际的一个场景&#xff0c; 那就是Flutter如何与原生&#xff08;Native&#xff09;端进行通信 目前看来&#xff0c;大概有三种方式&#xff0c;分别是&#xff1a; MethodChannel EventChannel MessageChann…

Redis配置与优化

目录 一、关系数据库与非关系型数据库 1、关系型数据库 2、非关系型数据库 3、关系型数据库和非关系型数据库区别 1、数据存储方式不同 2、扩展方式不同 3、对事务性的支持不同 二、Redis 1、简介 2、优点 3、缺点 4、使用场景 5、哪些数据适合放入缓存中 6、为什…

vue-cli脚手架创建创建的项目打包后无法正常打开报 Failed to load resource: net::ERR_FILE_NOT_FOUND错误

亲爱的小伙伴们&#xff0c;你们最近是否有遇到用使用最新的脚手架打包项目后index.html文件无法正常打开&#xff0c;然后控制台报错的情况呢&#xff0c;不要担心&#xff0c;这个坑今天被我踩到了并且被我解决了&#xff0c;下边就让我来给大家分享一下经验吧&#xff01; …

D. Maximum Subarray

Problem - 1796D - Codeforces 思路&#xff1a;想了个假dp做法推了半天&#xff0c;果然是dp。考虑用dp[i][j]表示以i结尾的&#xff0c;并且选择j个&#xff0b;x的最长连续子序列&#xff0c;那么如果我不选择第i位&#xff0c;那么会有f[i][j]max(w[i]-x,f[i-1][j]w[i]-x)&…

Kubernetes 的核心概念:Pod、Service 和 Namespace 解析

&#x1f337;&#x1f341; 博主 libin9iOak带您 Go to New World.✨&#x1f341; &#x1f984; 个人主页——libin9iOak的博客&#x1f390; &#x1f433; 《面试题大全》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33…

Linux共享库库+例子

1.什么是共享库&#xff1f;有什么优点&#xff1f;和静态库有什么区别&#xff1f; Linux动态库&#xff08;Dynamic Link Library&#xff0c;缩写为DLL&#xff09;是一种在Linux系统中使用的共享库&#xff08;Shared Library&#xff09;。与静态库不同&#xff0c;动态库…

飞机乘坐流程/怎么坐飞机

飞机乘坐流程/怎么坐飞机 编写原因对象人员经历背景飞机乘坐流程流程梗概订票去往机场办理登记牌/托运行李安检登机转机 飞行中下机 后记 编写原因 从上家单位裸辞&#xff0c;大概率下次不会找频繁出差的工作了&#xff0c;而日常出行应该也不会考虑飞机这种交通工具&#xf…

结构型设计模式之外观模式【设计模式系列】

系列文章目录 C技能系列 Linux通信架构系列 C高性能优化编程系列 深入理解软件架构设计系列 高级C并发线程编程 设计模式系列 期待你的关注哦&#xff01;&#xff01;&#xff01; 现在的一切都是为将来的梦想编织翅膀&#xff0c;让梦想在现实中展翅高飞。 Now everythi…

剑指YOLOv8改进最新MPDIoU损失函数:超越现有多种G/D/C/EIoU,23年7月首发论文,高效准确的边界框回归的损失

💡本篇内容:剑指YOLOv8改进最新MPDIoU损失函数:超越现有多种G/D/C/EIoU,23年7月首发论文,高效准确的边界框回归的损失 💡🚀🚀🚀本博客 改进源代码改进 适用于 YOLOv8 按步骤操作运行改进后的代码即可 💡:重点:该专栏《剑指YOLOv8原创改进》只更新改进 YOLO…

雷达信号处理自学总结(持续更新)

傅里叶变换的频率分辨率 频率分辨率 采样频率 信号长度 频率分辨率 \frac{采样频率 }{信号长度} 频率分辨率信号长度采样频率​ 可用numpy模块的fft.fftfreq函数求出傅里叶变换的频率分辨率。 https://numpy.org/doc/stable/reference/generated/numpy.fft.fftfreq.html

若依vue -【 44】

44 服务监控讲解 1 需求 显示CPU、内存、服务器信息、Java虚拟机信息、磁盘状态的信息 2 前端 RuoYi-Vue\ruoyi-ui\src\views\monitor\server\index.vue <script> import { getServer } from "/api/monitor/server";export default {name: "Server&quo…

JS(es6)同时给多个变量赋值

在ES6中&#xff0c;可以使用解构赋值语法同时给多个变量赋值。解构赋值语法可以从数组或对象中提取值&#xff0c;并将其赋给多个变量。 1. 数组解构赋值&#xff1a; const [var1, var2, var3] [1, 2, 3] console.log(var1); // 输出 1 console.log(var2); // 输出 2 cons…

前端技术搭建(动态图片)拖拽拼图!!(内含实现原理)

文章目录 前端技术搭建&#xff08;动态图片&#xff09;拖拽拼图(内含实现原理)导言功能介绍效果演示链接&#xff08;觉得不错的&#xff0c;请一键三连嘤嘤嘤&#xff09;项目目录页面搭建css样式设置工具函数游戏实现逻辑 开源地址总结 前端技术搭建&#xff08;动态图片&a…

什么是tcp rst以及什么时候产生?

rst包是仅在header control bits设置rst的空payload包&#xff0c;用于强制关闭tcp连接。常在以下场景发送 远程主机没有监听该端口 远程主机强迫关闭了一个现有连接。比如服务端进程崩溃后重启会向之前连接发送rst 相比于四次挥手的fin&#xff0c;rst是在异常情况下的无条…