import ( "github.com/pebbe/zmq4" ) func main() { socket, err := zmq4.NewSocket(zmq4.PUSH) if err != nil { panic(err) } defer socket.Close() endpoint := "tcp://localhost:5555" err = socket.Connect(endpoint) if err != nil { panic(err) } message := "hello world" _, err = socket.Send(message, 0) if err != nil { panic(err) } }
import ( "github.com/pebbe/zmq4" ) func main() { socket, err := zmq4.NewSocket(zmq4.PUSH) if err != nil { panic(err) } defer socket.Close() endpoint := "tcp://localhost:5555" err = socket.Connect(endpoint) if err != nil { panic(err) } message1 := "part 1" message2 := "part 2" message3 := "part 3" messages := []string{message1, message2, message3} for i, message := range messages { flag := zmq4.FlagNone if i == len(messages)-1 { flag = zmq4.FlagMore } _, err = socket.Send(message, flag) if err != nil { panic(err) } } }In the first example, we create a new PUSH socket, connect to an endpoint, and send a simple "hello world" message using Socket Send. In the second example, we send a multipart message consisting of three parts. We use the FlagMore flag to indicate that there are more parts to come. In both examples, we use the Socket Send function from the zmq4 package library.