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.

39 lines
721 B

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