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.

37 lines
700 B

10 years ago
10 years ago
10 years ago
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(protocol string, laddr string, c *Client) *Server {
  10. l := NewDefaultListener(protocol, laddr)
  11. s := &Server{
  12. listener: l,
  13. client: c,
  14. }
  15. go s.IncomingConnectionHandler()
  16. return s
  17. }
  18. func (s *Server) LocalAddress() *NetAddress {
  19. return s.listener.LocalAddress()
  20. }
  21. // meant to run in a goroutine
  22. func (s *Server) IncomingConnectionHandler() {
  23. for conn := range s.listener.Connections() {
  24. s.client.AddPeerWithConnection(conn, false)
  25. }
  26. }
  27. func (s *Server) Stop() {
  28. s.listener.Stop()
  29. s.client.Stop()
  30. }