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


Golang Socket.Send方法代碼示例

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


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

示例1: send

// This is simple send function here i communicate with raft using simple request-response socket and ask to raft their status
// like phase of raft and we can also close raft server using this function.
// Here msg :- 1 means msg for ask phase of server and msg:- 0 means close the raft server
func send(msg string, requester_C *zmq.Socket) string {

	// Decoding of phse receive by type 0 msg is 0 :- Follower, 1:- Candidate, 2:- Leader
	// By default phase :- "3" means no response from server and server is close
	requester_C.Send(msg, 0)
	phase := "3"
	if msg == "0" {
		return "0"
	}
	phase, _ = requester_C.Recv(0)
	type1 := s.Split(phase, " ")[0]
	value := s.Split(phase, " ")[1]
	if type1 == "-1" {
		if value == "0" {
			phase = "Follower"
		} else if value == "1" {
			phase = "Candidate"
		} else if value == "2" {
			phase = "Leader"
		}
	} else if type1 == "-2" {
		leaderId, _ = strconv.Atoi(value)
	} else if type1 == "0" {
		leaderId, _ = strconv.Atoi(s.Split(phase, " ")[2])
		msg_index, _ := strconv.Atoi(value)
		send(message[msg_index], requester[leaderId-1])
		return "0"
	} else {
	}
	return phase
}
開發者ID:rahulkishorwani,項目名稱:newrepo,代碼行數:34,代碼來源:raft_test.go

示例2: snapshots

func snapshots(socket *zmq.Socket, srv *clonesrv_t) (err error) {

	msg, err := socket.RecvMessage(0)
	if err != nil {
		return
	}
	identity := msg[0]

	//  Request is in second frame of message
	request := msg[1]
	if request != "ICANHAZ?" {
		err = errors.New("E: bad request, aborting")
		return
	}
	subtree := msg[2]

	//  Send state socket to client
	for _, kvmsg := range srv.kvmap {
		if key, _ := kvmsg.GetKey(); strings.HasPrefix(key, subtree) {
			socket.Send(identity, zmq.SNDMORE)
			kvmsg.Send(socket)
		}
	}

	//  Now send END message with sequence number
	log.Println("I: sending shapshot =", srv.sequence)
	socket.Send(identity, zmq.SNDMORE)
	kvmsg := kvmsg.NewKvmsg(srv.sequence)
	kvmsg.SetKey("KTHXBAI")
	kvmsg.SetBody(subtree)
	kvmsg.Send(socket)

	return
}
開發者ID:JeremyOT,項目名稱:zmq4,代碼行數:34,代碼來源:clonesrv6.go

示例3: r

func r(replier *zmq.Socket) {
	for {
		got, _ := replier.Recv(0)
		log.Println("Received", got)
		replier.Send(`{"jsonrpc":"2.0","id":"youpi","result":{"name":"test","hostname":"localtest","protocol":"test","port":0}}`, 0)
	}
}
開發者ID:LeReunionais,項目名稱:service,代碼行數:7,代碼來源:whereis_test.go

示例4: SendReply

// SendReply will send the reply back to the connected reply proxy
func SendReply(r *http.Response, body string, repsock *zmq.Socket) {
	rep := &messages.Reply{StatusCode: r.StatusCode, Body: body, Headers: r.Header}
	reps := rep.String()
	fmt.Printf("[PRIVATE] sending %d bytes or \n----\n%s\n-----\n", len(reps), reps)
	repsock.Send(reps, 0)
	fmt.Printf("[PRIVATE] sent %d bytes\n", len(reps))
}
開發者ID:xeb,項目名稱:backq,代碼行數:8,代碼來源:private.go

示例5: ZmqSendMulti

// ZmqSendMulti Sends a slice of strings as a multi-part message
func ZmqSendMulti(s *zmq.Socket, msg []string) {
	lastIdx := len(msg) - 1
	for idx, part := range msg {
		if idx == lastIdx {
			s.Send(part, 0)
		} else {
			s.Send(part, zmq.SNDMORE)
		}
	}
}
開發者ID:mahasak,項目名稱:workerpoolmanager,代碼行數:11,代碼來源:zmqwrapper.go

示例6: dealCmd

/******************************************************************************
* 概述:    訂閱退訂
* 函數名:    dealCmd
* 返回值:
* 參數列表:  參數名          參數類型      取值範圍     描述
*
*******************************************************************************/
func (this *ZmqSocket) dealCmd(cmdSocket *zmq4.Socket) (int, error) {
	log4.Debug("start deal cmd...")
	for { //半包處理
		cmdsStr, err0 := cmdSocket.Recv(zmq4.DONTWAIT)

		if err0 != nil {
			errno1 := zmq4.AsErrno(err0)
			switch errno1 {
			case zmq4.Errno(syscall.EAGAIN):
				return 0, nil
			case zmq4.Errno(syscall.EINTR):
				continue
			default:
				log4.Debug("zmq req Get err %v, %d!", errno1, errno1)
			}
		}
		if len(cmdsStr) == 0 {
			log4.Debug("deal cmd return")
			return 0, nil
		}
		ss := strings.Split(cmdsStr, " ")
		log4.Debug("recv cmd %s", cmdsStr)
		for i := 0; i < len(ss); i++ {
			if len(ss[i]) == 0 {
				continue
			}
			if ss[i] == "stop" {
				//				log4.Debug("recv cmd will stop %s %s", this.mreqUrl, this.msubUrl)
				cmdSocket.Send("0", 0)
				return 1, nil
			}
			if !this.mChoose {
				//				log4.Debug("recv cmd ,but notChoose so return")
				return 0, nil
			}
			if ss[i][0] == 'r' {
				if err := this.msubSocket.SetSubscribe(ss[i][1:]); err != nil {
					log4.Error("SetSubscribe(%s) falied, %s", ss[i][1:], err.Error())
					return 0, err
				}
				log4.Debug("setSubscribe ok %s", ss[i][1:])
				continue
			}
			if ss[i][0] == 'u' {
				if err := this.msubSocket.SetUnsubscribe(ss[i][1:]); err != nil {
					log4.Error("SetUnSubscribe(%s) falied, %s", ss[i][1:], err.Error())
					return 0, err
				}
				log4.Debug("setUnSubscribe ok %s", ss[i][1:])
				continue
			}
		}
	}
	return 0, nil
}
開發者ID:EdXu,項目名稱:Service-discovery-service-sds-,代碼行數:62,代碼來源:sdk_socket.go

示例7: send

func send(socket *zmq.Socket, update keyUpdate) error {
	var err error

	if _, err = socket.Send(update.key, zmq.SNDMORE); err != nil {
		return err
	}
	if _, err = socket.SendBytes(update.payload, 0); err != nil {
		return err
	}
	return nil
}
開發者ID:a-palchikov,項目名稱:kron,代碼行數:11,代碼來源:main.go

示例8: sendToClient

func sendToClient(message string, header []string, title string, more zmq.Flag, frontend *zmq.Socket) {

	//fmt.Println("\t", title)
	for key := range header {
		//fmt.Printf("\tSending to client: %s\n", header[key])
		frontend.Send(header[key], zmq.SNDMORE)
	}
	//fmt.Printf("\tSending to client: %s\n", message)
	frontend.Send(message, more)
	//fmt.Println("\tDone")
}
開發者ID:TomOgoma,項目名稱:GoZMQ,代碼行數:11,代碼來源:rrbroker.go

示例9: ListenUDPMcast

// args:
// - addr: multicast group/address to listen to
// - port: port number; addr:port builds the mcast socket
// - iface: name of network interface to listen to
// - d_dl_sock:
// - stopch:
func ListenUDPMcast(addr, port, iface string, d_dl_sock *zmq.Socket,
	stopch chan bool) {
	eth, err := net.InterfaceByName(iface)
	if err != nil {
		fmt.Println("Error interface:", err.Error())
		os.Exit(1)
	}

	group := net.ParseIP(addr)
	if group == nil {
		fmt.Println("Error: invalid group address:", addr)
		os.Exit(1)
	}

	// listen to all udp packets on mcast port
	c, err := net.ListenPacket("udp4", "0.0.0.0:"+port)
	if err != nil {
		fmt.Println("Error listening for mcast:", err.Error())
		os.Exit(1)
	}
	// close the listener when the application closes
	defer c.Close()

	// join mcast group
	p := ipv4.NewPacketConn(c)
	if err := p.JoinGroup(eth, &net.UDPAddr{IP: group}); err != nil {
		fmt.Println("Error joining:", err.Error())
		os.Exit(1)
	}
	fmt.Println("Listening on " + addr + ":" + port)

	// enable transmissons of control message
	if err := p.SetControlMessage(ipv4.FlagDst, true); err != nil {
		fmt.Println("Error control message", err.Error())
	}

	c1 := devreader.MakeChannel(UMSocket{p, group})

LOOP:
	for {
		select {
		case v1 := <-c1:
			fmt.Println("received UDP multicast")
			// forward to coord node
			d_dl_sock.Send(string(v1), 0)

		case <-stopch:
			break LOOP
		}

	}
}
開發者ID:herrfz,項目名稱:gowdc,代碼行數:58,代碼來源:udp_mcast.go

示例10: sendData

func sendData(socket *zmq.Socket, key string, data interface{}, kind string) {
	bs, err := json.Marshal(data)
	if err != nil {
		abort(err, "could not marshal data")
	}
	encoded_data := string(bs)
	msg_key := fmt.Sprintf("%s-%s,%s", opts.App, opts.Env, key)
	if _, err := socket.Send(msg_key, zmq.DONTWAIT|zmq.SNDMORE); err != nil {
		abort(err, "could not send message part 1")
	}
	if _, err := socket.Send(encoded_data, zmq.DONTWAIT); err != nil {
		abort(err, "could not send message part 2")
	}
	if opts.Verbose {
		fmt.Printf("KEY: %s\n%s: %s\n", key, kind, encoded_data)
	}
}
開發者ID:skaes,項目名稱:logjam-tools,代碼行數:17,代碼來源:generator.go

示例11: solve

func solve(hand string, sock *zmq.Socket) []string {
	req := &scrabble.Request{Hand: hand}

	reqMsg, err := proto.Marshal(req)
	condlog.Fatal(err, "Unable to marshal message")

	_, err = sock.Send(string(reqMsg), 0)
	condlog.Fatal(err, "Unable to marshal message")

	resMsg, err := sock.Recv(0)
	condlog.Fatal(err, "Unable to receive response")

	res := &scrabble.Response{}
	err = proto.Unmarshal([]byte(resMsg), res)
	condlog.Fatal(err, "Unable to unmarshal request")

	return res.Words
}
開發者ID:hjmat,項目名稱:scrabbled,代碼行數:18,代碼來源:client.go

示例12: send

// This is simple send function here i communicate with raft using simple request-response socket and ask to raft their status
// like phase of raft and we can also close raft server using this function.
// Here msg :- 1 means msg for ask phase of server and msg:- 0 means close the raft server
func send(msg int, requester *zmq.Socket) string {
	// Decoding of phse receive by type 0 msg is 0 :- Follower, 1:- Candidate, 2:- Leader

	// By default phase :- "3" means no response from server and server is close
	phase := "3"
	requester.Send(fmt.Sprintf("%d", msg), 0)
	if msg == 1 {
		phase, _ = requester.Recv(0)
	}
	if phase == "0" {
		phase = "Follower"
	} else if phase == "1" {
		phase = "Candidate"
	} else if phase == "2" {
		phase = "Leader"
	}
	return phase
}
開發者ID:prabhat-bajpai,項目名稱:kvstore-public,代碼行數:21,代碼來源:raft_test.go

示例13: serve

func serve(sock *zmq.Socket, solv *Solver) {
	for {
		requestMsg, err := sock.Recv(0)
		condlog.Fatal(err, "Unable to receive request")

		request := &scrabble.Request{}
		err = proto.Unmarshal([]byte(requestMsg), request)
		condlog.Fatal(err, "Unable to unmarshal request")

		result := solv.Solve(request.Hand)

		response := &scrabble.Response{Words: result}
		responseMsg, err := proto.Marshal(response)
		condlog.Fatal(err, "Unable to marshal response")

		_, err = sock.Send(string(responseMsg), 0)
		condlog.Fatal(err, "Unable to send response")
	}
}
開發者ID:hjmat,項目名稱:scrabbled,代碼行數:19,代碼來源:server.go

示例14: SendToClient

func SendToClient(signature, error_status, message string, frontend *zmq.Socket) {
	fmt.Printf("\tSending signature to client: %s\n", signature)
	frontend.Send(signature, zmq.SNDMORE)
	fmt.Printf("\tSending errorstatus to client: %s\n", error_status)
	frontend.Send(error_status, zmq.SNDMORE)
	fmt.Printf("\tSending message to client: %s\n", message)
	frontend.Send(message, 0)
}
開發者ID:TomOgoma,項目名稱:GoZMQ,代碼行數:8,代碼來源:library.go

示例15: TestConflate

func TestConflate(t *testing.T) {

	var s_in, s_out *zmq.Socket
	defer func() {
		for _, s := range []*zmq.Socket{s_in, s_out} {
			if s != nil {
				s.SetLinger(0)
				s.Close()
			}
		}
	}()

	bind_to := "tcp://127.0.0.1:5555"

	err := zmq.SetIoThreads(1)
	if err != nil {
		t.Fatal("SetIoThreads(1):", err)
	}

	s_in, err = zmq.NewSocket(zmq.PULL)
	if err != nil {
		t.Fatal("NewSocket 1:", err)
	}

	err = s_in.SetConflate(true)
	if err != nil {
		t.Fatal("SetConflate(true):", err)
	}

	err = s_in.Bind(bind_to)
	if err != nil {
		t.Fatal("s_in.Bind:", err)
	}

	s_out, err = zmq.NewSocket(zmq.PUSH)
	if err != nil {
		t.Fatal("NewSocket 2:", err)
	}

	err = s_out.Connect(bind_to)
	if err != nil {
		t.Fatal("s_out.Connect:", err)
	}

	message_count := 20

	for j := 0; j < message_count; j++ {
		_, err = s_out.Send(fmt.Sprint(j), 0)
		if err != nil {
			t.Fatalf("s_out.Send %d: %v", j, err)
		}
	}

	time.Sleep(time.Second)

	payload_recved, err := s_in.Recv(0)
	if err != nil {
		t.Error("s_in.Recv:", err)
	} else {
		i, err := strconv.Atoi(payload_recved)
		if err != nil {
			t.Error("strconv.Atoi:", err)
		}
		if i != message_count-1 {
			t.Error("payload_recved != message_count - 1")
		}
	}

	err = s_in.Close()
	s_in = nil
	if err != nil {
		t.Error("s_in.Close:", err)
	}

	err = s_out.Close()
	s_out = nil
	if err != nil {
		t.Error("s_out.Close:", err)
	}
}
開發者ID:pebbe,項目名稱:zmq4,代碼行數:80,代碼來源:zmq4_test.go


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