Beispiel #1
0
func NewHub(port int) *Hub {

	// listen on all interfaces
	ls, err := net.Listen("tcp", ":"+strconv.Itoa(port))

	log.Printf("Server begin listen at port: %d", port)

	//chec for connection error
	if err != nil {
		log.Fatalln(err)
		return nil
	}

	hub := &Hub{

		listener:  ls,
		quit:      make(chan bool),
		idPool:    idpool.NewReusableIdPool(),
		idSet:     set.New(),
		socketMap: syncmap.NewSyncMap(),
	}

	return hub

}
	sendInterval = 1
)

var (
	addr     string
	port     int
	pSize    int
	cliNum   int
	mexNum   int
	interval time.Duration
	showStat bool
)

var RelayMessage message.Message
var allStats *statbucket.StatBucket
var climap = syncmap.NewSyncMap()
var allCliId []uint64
var payload []byte
var messagesToRead int
var quitApp = make(chan bool)

var startTime time.Time
var endTime time.Time

var outMex, inMex, inByte, outByte int

func main() {

	a := flag.String("addr", Address, "address to connect")
	p := flag.Int("port", Port, "Define port number")
	s := flag.Int("size", payloadBytes, "Size of the payload to send [0-1024000]")