日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)GoFrame教程:GoFrameTCP組件-工具方法

?gtcp?模塊也提供了一些常用的工具方法。

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到武城網(wǎng)站設(shè)計(jì)與武城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站建設(shè)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)頁(yè)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋武城地區(qū)。

使用方式:

import "github.com/GOgf/gf/v2/net/gtcp"

接口文檔:

https://pkg.go.dev/github.com/gogf/gf/v2/net/gtcp

func LoadKeyCrt(crtFile, keyFile string) (*tls.Config, error)
func NewNetConn(addr string, timeout ...int) (net.Conn, error)
func NewNetConnKeyCrt(addr, crtFile, keyFile string) (net.Conn, error)
func NewNetConnTLS(addr string, tlsConfig *tls.Config) (net.Conn, error)
func Send(addr string, data []byte, retry ...Retry) error
func SendPkg(addr string, data []byte, option ...PkgOption) error
func SendPkgWithTimeout(addr string, data []byte, timeout time.Duration, option ...PkgOption) error
func SendRecv(addr string, data []byte, receive int, retry ...Retry) ([]byte, error)
func SendRecvPkg(addr string, data []byte, option ...PkgOption) ([]byte, error)
func SendRecvPkgWithTimeout(addr string, data []byte, timeout time.Duration, option ...PkgOption) ([]byte, error)
func SendRecvWithTimeout(addr string, data []byte, receive int, timeout time.Duration, retry ...Retry) ([]byte, error)
func SendWithTimeout(addr string, data []byte, timeout time.Duration, retry ...Retry) error

  1. ?NewNetConn?用于簡(jiǎn)化標(biāo)準(zhǔn)庫(kù)連接對(duì)象?net.Conn?的創(chuàng)建;
  2. ?NewNetConnTLS?和?NewNetConnKeyCrt?用于創(chuàng)建支持?TLS?安全加密通信的?TCP?客戶端;
  3. ?Send*?系列方法直接通過(guò)給定地址進(jìn)行數(shù)據(jù)發(fā)送,并獲取該請(qǐng)求的返回結(jié)果,用于短鏈接請(qǐng)求的情況;

以下為一個(gè)簡(jiǎn)單的示例,我們使用工具方法來(lái)訪問(wèn)指定的Web站點(diǎn):

package main

import (
    "fmt"
    "github.com/gogf/gf/v2/net/gtcp"
)

func main() {
    data, err := gtcp.SendRecv("www.baidu.com:80", []byte("HEAD / HTTP/1.1\n\n"), -1)
    if err != nil {
        panic(err)
    }
    fmt.Println(string(data))
}

在這個(gè)示例中,我們通過(guò)TCP訪問(wèn)百度首頁(yè),模擬HTTP請(qǐng)求頭信息,并獲得返回結(jié)果。 執(zhí)行后,輸出結(jié)果如下:

HTTP/1.1 302 Found
Connection: Keep-Alive
Content-Length: 17931
Content-Type: text/html
Date: Tue, 04 Jun 2019 15:53:09 GMT
Etag: "54d9749e-460b"
Server: bfe/1.0.8.18

分享題目:創(chuàng)新互聯(lián)GoFrame教程:GoFrameTCP組件-工具方法
標(biāo)題網(wǎng)址:http://www.dlmjj.cn/article/cdphoij.html