当前位置:网站首页>[golang] network connection net.dial
[golang] network connection net.dial
2022-07-29 01:51:00 【JavaPub-rodert】
Blogger introduction : We-Media JavaPub Independent maintainer , Fans all over the Internet 15w+,csdn Blogger 、java Quality creators in the field ,51ctoTOP10 Blogger , You know / Nuggets / Hua Wei Yun / Alibaba cloud /InfoQ And other high-quality authors 、 Focus on Java、
GoLangTechnical fields and sidelines .GoLang More convenient to learn , One article in hand , I have
GoLang interview | GoLang interview | GoLang interview
List of articles
Use chestnuts
conn, err := net.Dial("tcp", "google.com:80")
if err != nil {
// handle error
}
fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
status, err := bufio.NewReader(conn).ReadString('\n')
// ...
Source code
net.Dial Source code
// net.Dial Function interpretation
// The actual is Dialer.Dial An encapsulation of , After encapsulation , Can be called directly Dial dial , There is no need to define another Dialer Structure object , Use object dialing , The definition of structure object is omitted , The same name method used in packaging , Easy to remember
func Dial(network, address string) (Conn, error) {
var d Dialer // Defined a Dialer Structure object , Use the Dial Method to dial , therefore net.Dial The actual is Dialer.Dial An encapsulation of
return d.Dial(network, address)
}
usage
All in all ,dial Just made some presets , And a connection object is returned .
On the Internet network Upper connection address address, And return a Conn Interface .
Available network types : “tcp”、“tcp4”、“tcp6”、“udp”、“udp4”、“udp6”、“ip”、“ip4”、“ip6”、“unix”、“unixgram”、“unixpacket”
https://www.apiref.com/go-zh/net.htm#Dial


边栏推荐
- JVM learning minutes
- 【HCIP】两个MGRE网络通过OSPF实现互联(eNSP)
- T-sne降维
- BOM系列之定时器
- JS 定时器setInterval clearInterval 延时器setTimeOut 异步 动画
- JS event introduction
- [7.21-26] code source - [sports festival] [Dan fishing war] [maximum weight division]
- Autoware reports an error: can't generate global path for start solution
- Code reading - ten C open source projects
- 把逻辑做在Sigma-DSP中的优化实例-数据分配器
猜你喜欢

Autoware reports an error: can't generate global path for start solution

承办首届算力大会,济南胜在何处?

Anaconda environment installation problem

我们总结了 3 大Nacos使用建议,并首次公开 Nacos 3.0 规划图 Nacos 开源 4 周年
![[hcip] MPLS Foundation](/img/91/a2aebf333fb3e3fedf0fc393e175a9.png)
[hcip] MPLS Foundation

Reinforcement learning (III): dqn, nature dqn, double dqn, with source code interpretation

5G 商用第三年:无人驾驶的“上山”与“下海”

Day01作业

JVM learning minutes

What are the common cyber threats faced by manufacturers and how do they protect themselves
随机推荐
BOM系列之定时器
After understanding the composition of the URL of the website, we use the URL module, querystring module and mime module to improve the static website
覆盖接入2w+交通监测设备,EMQ为深圳市打造交通全要素数字化新引擎
numpy.where() 用法和np.argsort()的用法
It is found that the data of decimal type in the database can be obtained through resultset.getdouble, but this attribute cannot be obtained through GetObject.
LeetCode 113:路径总和 II
【7.27】代码源 - 【删数】【括号序列】【数字替换】【游戏】【画画】
How many of the top ten test tools in 2022 do you master
560 和为 K 的子数组
Understand various paths
Plato launched the LAAS protocol elephant swap, which allows users to earn premium income
matplotlib中文问题
Where will Jinan win in hosting the first computing power conference?
【HCIP】MGRE环境下OSPF实验,含多进程双向重发布及OSPF特殊区域
[understanding of opportunity-54]: plain book-1-the origin of things [original chapter 1]: the road is simple.
T-sne dimensionality reduction
2022年最火的十大测试工具,你掌握了几个
How to protect WordPress website from network attack? It is essential to take safety measures
ELS square movement
JS event introduction
