新聞中心
這里有您想知道的互聯(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- ?
NewNetConn?用于簡(jiǎn)化標(biāo)準(zhǔn)庫(kù)連接對(duì)象?net.Conn?的創(chuàng)建; - ?
NewNetConnTLS?和?NewNetConnKeyCrt?用于創(chuàng)建支持?TLS?安全加密通信的?TCP?客戶端; - ?
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


咨詢
建站咨詢
