当前位置:网站首页>[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


边栏推荐
- BOM系列之定时器
- PCL point cloud intensity image
- Plato launched the LAAS protocol elephant swap, which allows users to earn premium income
- LeetCode 113:路径总和 II
- Reinforcement learning (III): dqn, nature dqn, double dqn, with source code interpretation
- 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.
- Ruiji takeout project actual battle day01
- [hcip] OSPF experiment under mGRE environment, including multi process bidirectional republication and OSPF special area
- matplotlib中文问题
- 围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
猜你喜欢

The information security and Standardization Commission issued the draft for comments on the management guide for app personal information processing activities

Merkel Studio - harmonyos implementation list to do

Read the recent trends of okaleido tiger and tap the value and potential behind it

Cloud native application comprehensive exercise

【Golang】- runtime.Goexit()

BOM系列之定时器

BOM系列之window对象

Plato launched the LAAS protocol elephant swap, which allows users to earn premium income

10 major network security incidents in the past 10 years
![[hcip] OSPF experiment under mGRE environment, including multi process bidirectional republication and OSPF special area](/img/07/565ca7145bcbef2d467b3c860b7487.png)
[hcip] OSPF experiment under mGRE environment, including multi process bidirectional republication and OSPF special area
随机推荐
DSP震动座椅
【7.27】代码源 - 【删数】【括号序列】【数字替换】【游戏】【画画】
TypeError: can only concatenate str (not “int“) to str
承办首届算力大会,济南胜在何处?
internship:用于类型判断的工具类编写
What are source code, inverse code and complement code
剑指offer专项突击版第13天
Where will Jinan win in hosting the first computing power conference?
【HCIP】两个MGRE网络通过OSPF实现互联(eNSP)
StoneDB 邀请您参与开源社区月会!
Day01作业
TDA75610-I2C-模拟功放I2C地址的确定
T-sne降维
Code reading - ten C open source projects
ELS stop at all
10 major network security incidents in the past 10 years
我们总结了 3 大Nacos使用建议,并首次公开 Nacos 3.0 规划图 Nacos 开源 4 周年
[netding cup 2020 rosefinch group]nmap
What is the ISO assessment? How to do the waiting insurance scheme
For a safer experience, Microsoft announced the first PC with a secure Pluto chip