Example #1
0
func NewClientGogueConn(connectTo string) *gogueconn.GogueConn {
	conn, err := net.Dial("tcp", connectTo)
	if err != nil {
		log.Error("client %v", err)
		return nil
	}
	return gogueconn.New(conn)
}
Example #2
0
func TCPServer(listenString string, connNum int, connThrottle int, runConn ServerGoFn) {
	log.Info("Start server %v", listenString)
	// concurrent connection count control
	clientQueue := make(chan bool, connNum)

	listener, err := net.Listen("tcp", listenString)
	if err != nil {
		log.Error("%v", err)
		return
	}
	defer listener.Close()

	for {
		time.Sleep(time.Duration(connThrottle) * time.Millisecond)
		clientQueue <- true
		conn, err := listener.Accept()
		if err != nil {
			log.Error("%v", err)
		} else {
			go runConn(gogueconn.New(conn), clientQueue)
		}
	}
}