func GetServer(serverClass string, serverAddress string) (iface.IServer, error) { listener, err := net.Listen("tcp", serverAddress) if err != nil { return nil, err } if serverClass == SIMPLE_SERVER { log.Info("Listening at %s", serverAddress) return NewSimpleServer(listener), nil } return nil, errors.New("Invalid server class!") }
// Connection dispatcher. Entry point to start connection handling. func (s *SessionHandler) DispatchConn() { go s.quitListenter() addr := s.conn.RemoteAddr().String() log.Info("Client connected: %s", addr) s.writeResponse(common.NewStrResponse("HELLO FIREMPQ-0.1")) for s.active { cmdTokens, err := s.tokenizer.ReadTokens(s.conn) if err == nil { err = s.processCmdTokens(cmdTokens) } if err != nil { errTxt := err.Error() if err != io.EOF && !(strings.Index(errTxt, "use of closed") > 0) { log.Error(errTxt) } break } } log.Debug("Client disconnected: %s", addr) }
func (this *CommandServer) Stop() { log.Notice("Server has been told to stop.") log.Info("Disconnection all clients...") this.listener.Close() close(this.quitChan) }
func (this *CommandServer) Shutdown() { this.waitGroup.Wait() log.Info("Closing database...") this.facade.Close() log.Info("Server stopped.") }