示例#1
0
func (m *MqttSvc) Host(mport int) {
	Mport = mport
	server, err := transport.Launch("tcp://:" + strconv.Itoa(Mport))
	if err != nil {
		panic(err)
	}
	m.Engine = broker.NewEngine()
	m.Engine.Accept(server)
}
示例#2
0
func fakeBroker(t *testing.T, testFlows ...*tools.Flow) (chan struct{}, string) {
	done := make(chan struct{})

	server, err := transport.Launch("tcp://localhost:0")
	assert.NoError(t, err)

	go func() {
		for _, flow := range testFlows {
			conn, err := server.Accept()
			assert.NoError(t, err)

			flow.Test(t, conn)
		}

		err = server.Close()
		assert.NoError(t, err)

		close(done)
	}()

	_, port, _ := net.SplitHostPort(server.Addr().String())

	return done, port
}