예제 #1
0
파일: client.go 프로젝트: daemonl/connor
func do(name string) {
	for {
		conn := connor.TinyHandshakeDial(brokerAddress)
		// Establish a connection, retry indefinately.
		logf("Connected %s [%s]", name, brokerAddress)

		scanner := bufio.NewScanner(conn)
		for i := 0; i < 4; i++ {
			n, err := conn.Write([]byte(fmt.Sprintf("%d\n", i)))
			if err != nil {
				logf(err.Error())
				continue
			}
			logf("wrote %d bytes on %s", n, name)

			if !scanner.Scan() {
				break
			}
			line := scanner.Text()
			logf("%s GOT: %s", name, line)
		}
		conn.Close()
		logf("Connection Ended %s [%s]", name, brokerAddress)
	}
}
예제 #2
0
파일: worker.go 프로젝트: daemonl/connor
func do() error {
	for {
		// Establish a connection, retry indefinately.
		conn := connor.TinyHandshakeDial(brokerAddress)
		logf("Connected [%s]", brokerAddress)

		scanner := bufio.NewScanner(conn)
		for scanner.Scan() {
			line := scanner.Text()
			logf("Got %s", line)
			time.Sleep(time.Second)
			conn.Write([]byte("hello " + line + "\n"))
		}
		conn.Close()
		logf("Connection Ended [%s]", brokerAddress)
	}
}