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

package peer
import (
"sync/atomic"
"net"
)
/* Server */
type Server struct {
listener Listener
client *Client
}
func NewServer(protocol string, laddr string, c *Client) *Server {
l := NewListener(protocol, laddr)
s := &Server{
listener: l,
client: c,
}
go s.IncomingConnectionHandler()
return s
}
func (s *Server) LocalAddress() *NetAddress {
return s.listener.LocalAddress()
}
// meant to run in a goroutine
func (s *Server) IncomingConnectionHandler() {
for conn := range s.listener.Connections() {
s.client.AddPeerWithConnection(conn, false)
}
}
func (s *Server) Stop() {
s.listener.Stop()
s.client.Stop()
}