You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
550 B

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package peer
  2. import (
  3. )
  4. /* Server */
  5. type Server struct {
  6. listener Listener
  7. client *Client
  8. }
  9. func NewServer(l Listener, c *Client) *Server {
  10. s := &Server{
  11. listener: l,
  12. client: c,
  13. }
  14. go s.IncomingConnectionHandler()
  15. return s
  16. }
  17. // meant to run in a goroutine
  18. func (s *Server) IncomingConnectionHandler() {
  19. for conn := range s.listener.Connections() {
  20. s.client.AddPeerWithConnection(conn, false)
  21. }
  22. }
  23. func (s *Server) Stop() {
  24. s.listener.Stop()
  25. s.client.Stop()
  26. }