Beispiel #1
0
func (s *socket) Bind(endpoint string) (net.Addr, error) {
	var addr net.Addr

	if !s.asServer {
		return addr, ErrInvalidSockAction
	}

	parts := strings.Split(endpoint, "://")

	ln, err := net.Listen(parts[0], parts[1])
	if err != nil {
		return addr, err
	}

	netconn, err := ln.Accept()
	if err != nil {
		return addr, err
	}

	zmtpconn := zmtp.NewConnection(netconn)
	_, err = zmtpconn.Prepare(s.mechanism, s.sockType, s.asServer, nil)
	if err != nil {
		return netconn.LocalAddr(), err
	}

	s.msgChan, s.cmdChan, s.errChan = zmtpconn.Recv()

	conn := &Connection{
		netconn:  netconn,
		zmtpconn: zmtpconn,
	}

	s.conns = append(s.conns, conn)
	return netconn.LocalAddr(), nil
}
Beispiel #2
0
func (s *socket) Connect(endpoint string) error {
	if s.asServer {
		return ErrInvalidSockAction
	}

	parts := strings.Split(endpoint, "://")

Connect:
	netconn, err := net.Dial(parts[0], parts[1])
	if err != nil {
		time.Sleep(s.GetRetry())
		goto Connect
	}

	zmtpconn := zmtp.NewConnection(netconn)
	_, err = zmtpconn.Prepare(s.mechanism, s.sockType, s.asServer, nil)
	if err != nil {
		return err
	}

	s.msgChan, s.cmdChan, s.errChan = zmtpconn.Recv()

	conn := &Connection{
		netconn:  netconn,
		zmtpconn: zmtpconn,
	}

	s.conns = append(s.conns, conn)
	return nil
}