當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Dialer.KeepAlive方法代碼示例

本文整理匯總了Golang中net.Dialer.KeepAlive方法的典型用法代碼示例。如果您正苦於以下問題:Golang Dialer.KeepAlive方法的具體用法?Golang Dialer.KeepAlive怎麽用?Golang Dialer.KeepAlive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.Dialer的用法示例。


在下文中一共展示了Dialer.KeepAlive方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewClient

func NewClient(originURL, targetURL string, settings map[string]interface{}) (c *websocket.Conn, response *http.Response, err error) {
	u, err := url.Parse(targetURL)
	if err != nil {
		return nil, nil, err
	}

	dialer := net.Dialer{}

	timeoutInterface, ok := settings["Timeout"]
	if ok {
		dialer.Timeout = timeoutInterface.(time.Duration)
	}

	keepAliveInterface, ok := settings["KeepAlive"]
	if ok {
		dialer.KeepAlive = keepAliveInterface.(time.Duration)
	}

	rawConn, err := dialer.Dial("tcp", u.Host)
	if err != nil {
		logrus.WithFields(logrus.Fields{
			"Error": err.Error(),
		}).Errorf("TCP connection error when dialing %v", u.Host)

		return nil, nil, err
	}

	wsHeaders := http.Header{
		"Origin": {originURL},
		// your milage may differ
		"Sec-WebSocket-Extensions": {"permessage-deflate; client_max_window_bits, x-webkit-deflate-frame"},
	}

	return websocket.NewClient(rawConn, u, wsHeaders, 1024, 1024)
}
開發者ID:actaeon,項目名稱:resourced,代碼行數:35,代碼來源:wstrafficker.go

示例2: ConnectSrv

func ConnectSrv(Config ConfigT) net.Conn {
	var dialer net.Dialer
	dialer.Timeout = time.Second
	dialer.KeepAlive = time.Minute
	chandesc, err := dialer.Dial("tcp", ConcatStr(":", Config.Main.Server, Config.Main.Port))
	if err != nil {
		LogErr(err, "serv dial")
		return nil
	} else {
		var send string = Config.Main.CCID
		for _, target := range Config.Main.TargetID {
			send = ConcatStr(" ", send, target)
		}
		fmt.Fprintf(chandesc, "%s", send)
		return chandesc
	}
}
開發者ID:fffilimonov,項目名稱:BW_CCC,代碼行數:17,代碼來源:main.go

示例3: Dial

func Dial(_s Stream) (err error) {
	switch w := _s.(type) {
	case *wrapperStream:
		switch s := w.base.(type) {
		case *dummyStream:
			x := &xmppStream{to: s.to, onCloseFunc: w.onErrorFunc}
			var (
				host, port string
				dial       net.Dialer
			)
			if host, port, err = srv.Resolve(x.to); err == nil {
				dial.KeepAlive = 10 * time.Second
				if x.conn, err = dial.Dial("tcp", host+":"+port); err == nil {
					x.ctrl = make(chan bool)
					x.data = make(chan pack, 256)
					go func(stream *xmppStream) {
						<-stream.ctrl
						stream.conn.Close()
					}(x)

					doSplit := func(stream *xmppStream, onErr func(error)) {
						for data := range spl1t(stream.conn, onErr) {
							//log.Println("SPLIT")
							//log.Println(string(data))
							//log.Println()
							stream.data <- pack{data: data, hash: adler32.Checksum(data)}
						}
					}

					var onErr func(error)
					onErr = func(_err error) {
						switch e := _err.(type) {
						case net.Error:
							if e.Temporary() {
								go doSplit(x, onErr)
							} else {
								x.closeStream()
								x.onClose(e)
								w.base = s
							}
						default:
							panic(fmt.Sprint(reflect.TypeOf(e), e))
						}
					}

					go doSplit(x, onErr)
					w.base = x
				} else {
					x.onClose(err)
				}
			} else {
				x.onClose(err)
			}
		default:
			err = errors.New("already connected")
		}
	default:
		halt.As(100, reflect.TypeOf(_s))
	}
	return
}
開發者ID:kpmy,項目名稱:xippo,代碼行數:61,代碼來源:stream.go


注:本文中的net.Dialer.KeepAlive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。