当前位置: 首页>>代码示例>>Golang>>正文


Golang Conn.SetTimeout方法代码示例

本文整理汇总了Golang中net.Conn.SetTimeout方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.SetTimeout方法的具体用法?Golang Conn.SetTimeout怎么用?Golang Conn.SetTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.Conn的用法示例。


在下文中一共展示了Conn.SetTimeout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: client

func client(conn net.Conn) {
	err := conn.SetTimeout(1000000000)
	handleErr(err)

	bytes := make([]byte, 20)
	_, err = conn.Read(bytes)
	if err != nil {
		fmt.Println("Error: Connection failed with", conn.RemoteAddr().String())
		fmt.Println("Error:", err)
		return
	}

	serverId := compliment(bytes[0:4])
	userId := compliment(bytes[4:8])
	missionId := compliment(bytes[8:12])

	req := hts + "rms.php?ip=" + conn.RemoteAddr().String()
	req = req + "&serverId=" + serverId
	req = req + "&userId=" + userId
	req = req + "&missionId=" + missionId

	response, err := http.Get(req)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	buffer := make([]byte, 1024)
	n, err := response.Body.Read(buffer)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	output := buffer[0:n]
	if string(output) == "true" {
		fmt.Print("Notice: Successfully marked mission.  ")
	} else {
		fmt.Print("Error:  Access denied to mark mission.  ")
	}

	fmt.Println(serverId, "-", userId, "-", missionId)
	conn.Close()
}
开发者ID:HBHRP,项目名称:HackThisSite,代码行数:44,代码来源:rms.go

示例2: handleAudienceRequest

func handleAudienceRequest(c net.Conn) {
	defer c.Close()

	c.SetTimeout(0)
	r, _ := c.(io.Reader)
	w, _ := c.(io.Writer)
	dec := json.NewDecoder(r)
	enc := json.NewEncoder(w)

	outobj := new(GenericJsonRequest)
	err := dec.Decode(outobj)
	if err != nil {
		o.Warn("Error decoding JSON talking to audience: %s", err)
		return
	}

	if nil == outobj.Op {
		o.Warn("Malformed JSON message talking to audience.  Missing Op")
		return
	}
	switch *(outobj.Op) {
	case "status":
		if nil == outobj.Id {
			o.Warn("Malformed Status message talking to audience. Missing Job ID")
			return
		}
		job := o.JobGet(*outobj.Id)
		jresp := new([2]interface{})
		if nil != job {
			jresp[0] = "OK"
			iresp := NewJsonStatusResponse()
			switch job.State {
			case o.JOB_PENDING:
				iresp.Status = "PENDING"
			case o.JOB_SUCCESSFUL:
				iresp.Status = "OK"
			case o.JOB_FAILED_PARTIAL:
				iresp.Status = "PARTIAL_FAIL"
			case o.JOB_FAILED:
				iresp.Status = "FAIL"
			default:
				o.Fail("Blargh.  %d is an unknown job state!", job.State)
			}
			resnames := o.JobGetResultNames(*outobj.Id)
			for i := range resnames {
				tr := o.JobGetResult(*outobj.Id, resnames[i])
				if nil != tr {
					presp := NewJsonPlayerStatus()
					switch tr.State {
					case o.RESP_RUNNING:
						presp.Status = "PENDING"
					case o.RESP_FINISHED:
						presp.Status = "OK"
					case o.RESP_FAILED:
						presp.Status = "FAIL"
					case o.RESP_FAILED_UNKNOWN_SCORE:
						presp.Status = "UNK_SCORE"
					case o.RESP_FAILED_HOST_ERROR:
						presp.Status = "HOST_ERROR"
					case o.RESP_FAILED_UNKNOWN:
						presp.Status = "UNKNOWN_FAILURE"
					}
					for k, v := range tr.Response {
						presp.Response[k] = v
					}
					iresp.Players[resnames[i]] = presp
				}

			}
			jresp[1] = iresp
		} else {
			jresp[0] = "Error"
			jresp[1] = nil
		}
		enc.Encode(jresp)
		o.Debug("Status...")
	case "queue":
		if nil == outobj.Score {
			o.Warn("Malformed Queue message talking to audience. Missing Score")
			sendQueueFailureResponse("Missing Score", enc)
			return
		}
		if nil == outobj.Scope {
			o.Warn("Malformed Queue message talking to audience. Missing Scope")
			sendQueueFailureResponse("Missing Scope", enc)
			return
		}
		if nil == outobj.Players || len(outobj.Players) < 1 {
			o.Warn("Malformed Queue message talking to audience. Missing Players")
			sendQueueFailureResponse("Missing Players", enc)
			return
		}
		for _, player := range outobj.Players {
			if !HostAuthorised(player) {
				o.Warn("Malformed Queue message - unknown player %s specified.", player)
				sendQueueFailureResponse("Invalid Player", enc)
				return
			}
		}
		job := NewRequest()
//.........这里部分代码省略.........
开发者ID:juilyoon,项目名称:Orchestra,代码行数:101,代码来源:audience.go

示例3: NewTServerSocketConnTimeout

func NewTServerSocketConnTimeout(conn net.Conn, nsecClientTimeout int64) *TServerSocket {
	v := &TServerSocket{conn: conn, addr: conn.LocalAddr(), nsecClientTimeout: nsecClientTimeout}
	conn.SetTimeout(nsecClientTimeout)
	return v
}
开发者ID:QwertyManiac,项目名称:Impala,代码行数:5,代码来源:tserver_socket.go


注:本文中的net.Conn.SetTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。