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


边栏推荐
- What are source code, inverse code and complement code
- Platofarm community ecological gospel, users can get premium income with elephant swap
- Come on, handwritten RPC S2 serialization exploration
- 动态内存与智能指针
- ELS new box falls
- PCL point cloud intensity image
- 【golang】使用select {}
- Focus on differentiated product design, intelligent technology efficiency improvement and literacy education around new citizen Finance
- SiC Power Semiconductor Industry Summit Forum successfully held
- [网鼎杯 2020 朱雀组]Nmap
猜你喜欢

LeetCode 113:路径总和 II

承办首届算力大会,济南胜在何处?
![[netding cup 2020 rosefinch group]nmap](/img/22/1fdf716a216ae26b9110b2e5f211f6.png)
[netding cup 2020 rosefinch group]nmap

Anaconda environment installation problem

【流放之路-第八章】

【公开课预告】:快手GPU/FPGA/ASIC异构平台的应用探索
![[observation] ranked first in SaaS of pure public cloud in three years, and yonsuite's](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[observation] ranked first in SaaS of pure public cloud in three years, and yonsuite's "flywheel effect"

易观分析:以用户为中心,提升手机银行用户体验,助力用户价值增长

规划数学期末考试模拟二

【流放之路-第七章】
随机推荐
【流放之路-第六章】
使用POI,实现excel文件导出,图片url导出文件,图片和excel文件导出压缩包
Come on, handwritten RPC S2 serialization exploration
把逻辑做在Sigma-DSP中的优化实例-数据分配器
560 和为 K 的子数组
Where will Jinan win in hosting the first computing power conference?
AlphaFold揭示了蛋白质结构宇宙-从近100万个结构扩展到超过2亿个结构
TypeError: can only concatenate str (not “int“) to str
How to protect WordPress website from network attack? It is essential to take safety measures
【GoLang】同步锁 Mutex
【Golang】- runtime.Goexit()
[7.27] code source - [deletion], [bracket sequence], [number replacement], [game], [painting]
【Web技术】1395- Esbuild Bundler HMR
J9 number theory: what factors determine the value of NFT?
Cloud native application comprehensive exercise
560 and K
[WesternCTF2018]shrine
【流放之路-第八章】
JS事件简介
【10点公开课】:快手GPU/FPGA/ASIC异构平台的应用探索
