当前位置: 首页>>代码示例>>Golang>>正文


Golang textproto.Dial函数代码示例

本文整理汇总了Golang中net/textproto.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Dial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Connect

// Connect initializes the connection to the specified ftp server address.
//
// It is generally followed by a call to Login() as most FTP commands require
// an authenticated user.
func Connect(addr string) (*ServerConn, error) {
	conn, err := textproto.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}

	host, _, err := net.SplitHostPort(addr)
	if err != nil {
		conn.Close()
		return nil, err
	}
	c := &ServerConn{
		conn:     conn,
		host:     host,
		features: make(map[string]string),
	}

	_, _, err = c.conn.ReadResponse(StatusReady)
	if err != nil {
		c.Quit()
		return nil, err
	}

	err = c.feat()
	if err != nil {
		c.Quit()
		return nil, err
	}

	return c, nil
}
开发者ID:nieware,项目名称:goftp,代码行数:35,代码来源:ftp.go

示例2: Dial

// Dial the beanstalkd server at remote address addr.
func Dial(addr string, onConnect func(*Conn)) (*Conn, os.Error) {
	textConn, err := textproto.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}
	return newConn(addr, textConn, onConnect), nil
}
开发者ID:edsrzf,项目名称:beanstalk.go,代码行数:8,代码来源:beanstalk.go

示例3: Connect

// Connect initializes the connection to the specified ftp server address.
//
// It is generally followed by a call to Login() as most FTP commands require
// an authenticated user.
func Connect(addr string) (*ServerConn, error) {
	conn, err := textproto.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}

	a := strings.SplitN(addr, ":", 2)
	c := &ServerConn{
		conn:     conn,
		host:     a[0],
		features: make(map[string]string),
	}

	_, _, err = c.conn.ReadResponse(StatusReady)
	if err != nil {
		c.Quit()
		return nil, err
	}

	err = c.feat()
	if err != nil {
		c.Quit()
		return nil, err
	}

	return c, nil
}
开发者ID:darxen,项目名称:goftp,代码行数:31,代码来源:ftp.go

示例4: DialFtp

func DialFtp(addr string) (*FtpConn, os.Error) {
	conn, err := proto.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}
	return &FtpConn{PreLogin, 0, conn}, nil
}
开发者ID:juster,项目名称:maw,代码行数:7,代码来源:ftp.go

示例5: New

// New connects to an NNTP server.
// The network and addr are passed to net.Dial to
// make the connection.
//
// Example:
//   conn, err := nntp.Dial("tcp", "my.news:nntp")
//
func New(network, addr string) (*Conn, error) {
	c, err := textproto.Dial(network, addr)
	if err != nil {
		return nil, err
	}
	return newClient(c)
}
开发者ID:hobeone,项目名称:nntp,代码行数:14,代码来源:nntp.go

示例6: cmd

func (c *Conn) cmd(response, format string, a ...interface{}) *result {
	err := c.textConn.PrintfLine(format, a...)
	for tries := 0; err != nil && tries < retryCount; tries++ {
		c.textConn, err = textproto.Dial("tcp", c.Name)
		if err != nil {
			continue
		}
		if c.onConnect != nil {
			c.onConnect(c)
		}
		err = c.textConn.PrintfLine(format, a...)
	}
	if err != nil {
		return &result{err: err}
	}

	str, err := c.textConn.ReadLine()
	if err != nil {
		return &result{err: err}
	}

	var res result
	res.line = str
	args := strings.Fields(str)
	res.name = args[0]
	res.args = args[1:]
	res.setError(response)
	res.readBody(c.textConn.R)
	return &res
}
开发者ID:edsrzf,项目名称:beanstalk.go,代码行数:30,代码来源:beanstalk.go

示例7: main

func main() {

	// read log file todo: move in function
	cfgFile, _ := os.Open("bot.json")
	decoder := json.NewDecoder(cfgFile)
	cfg := Configuration{}
	err := decoder.Decode(&cfg)
	if err != nil {
		fmt.Println("ERROR cfg: ", err)
		return
	}
	// end config read

	// Build bot
	bot := new(Bot)
	bot.activeAdmins = make(map[string]bool)
	bot.voted = make(map[string]bool)
	bot.suggestions = make(map[int]Title)
	bot.writeChan = make(chan *IrcMessage)
	bot.config = &cfg
	// connect to the server
	bot.conn, err = textproto.Dial("tcp", cfg.Host+":"+cfg.Port)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return
	}
	bot.startBot()
}
开发者ID:JSchwehn,项目名称:GoIrcBot,代码行数:28,代码来源:main.go

示例8: Dial

// Dial connects to the address with the nickname
// and returns a Conn
func Dial(conf *Configuration) Context {
	initLogger(conf.Verbose)
	conn := &Connection{
		address:  fmt.Sprintf("%s:%d", conf.Hostname, conf.Port),
		nickname: conf.Nickname,

		ch: &Channels{m: make(map[string]*Channel)},
		ev: NewEvents(),

		done: make(chan struct{}),
	}

	log.Debugf("connecting to %s", conn.address)
	tp, err := textproto.Dial("tcp", conn.address)
	if err != nil {
		log.Fatalf(err.Error())
	}

	conn.conn = tp
	if conf.Password != "" {
		conn.Raw("PASS %s", conf.Password)
	}

	conn.Raw("NICK %s", conf.Nickname)
	conn.Raw("USER %s 0 * :%s", conf.Username, conf.Realname)

	log.Debugf("starting readLoop")
	go conn.readLoop()
	return conn
}
开发者ID:j6n,项目名称:anolis,代码行数:32,代码来源:connection.go

示例9: Dial

// Dial uses a provided addr:port and opens a connection, returning any error
func (c *Connection) Dial(addr string) (err error) {
	tp, err := textproto.Dial("tcp", addr)
	if err != nil {
		return err
	}

	c.conn = tp
	return
}
开发者ID:j6n,项目名称:noye,代码行数:10,代码来源:conn.go

示例10: connect

func (ep *endpoint) connect() error {
	conn, err := textproto.Dial("tcp", fmt.Sprintf("%s:%d", ep.Host, ep.Port))
	if err != nil {
		ep.Error = err
		return err
	}
	ep.Conn = conn
	log.Printf("Connected to endpoint")
	return nil
}
开发者ID:ScottBrooks,项目名称:gocuc,代码行数:10,代码来源:runner.go

示例11: buildConnection

func buildConnection(addr string, useTls bool) (*textproto.Conn, error) {
	if useTls == true {
		tls, err := tls.Dial("tcp", addr, nil)
		if err != nil {
			return nil, err
		}
		return textproto.NewConn(tls), nil
	} else {
		return textproto.Dial("tcp", addr)
	}
	return nil, errors.New("could not build connection")
}
开发者ID:peterkeen,项目名称:macguffin,代码行数:12,代码来源:client.go

示例12: Connect

func (bot *Bot) Connect() {
	conn, err := textproto.Dial("tcp", bot.server+":"+bot.port)
	if err != nil {
		log.Fatal("unable to connect to IRC server", err)
	}
	bot.conn = conn
	log.Printf("Connected to IRC server %s:%s\n", bot.server, bot.port)

	userCommand := fmt.Sprintf("USER %s 8 * :%s\n", bot.user, bot.user)
	bot.conn.PrintfLine(userCommand)
	bot.conn.PrintfLine("NICK " + bot.nick)
}
开发者ID:GDG-Korea,项目名称:Andnyang,代码行数:12,代码来源:bot.go

示例13: Dial

// Dial an APRS-IS service.
func Dial(prot, addr string) (rv *APRSIS, err error) {
	var conn *textproto.Conn
	conn, err = textproto.Dial(prot, addr)
	if err != nil {
		return
	}

	return &APRSIS{conn: conn,
		rawLog:      ioutil.Discard,
		infoHandler: dumbInfoHandler,
	}, nil
}
开发者ID:dustin,项目名称:go-aprs,代码行数:13,代码来源:aprsis.go

示例14: Dial

// Dial returns a new client connected to a dictionary server at
// addr on the given network.
func Dial(network, addr string) (*Client, error) {
	text, err := textproto.Dial(network, addr)
	if err != nil {
		return nil, err
	}
	_, _, err = text.ReadCodeLine(220)
	if err != nil {
		text.Close()
		return nil, err
	}
	return &Client{text: text}, nil
}
开发者ID:2722,项目名称:lantern,代码行数:14,代码来源:dict.go

示例15: Dial

func Dial(network, address string) (*Conn, error) {
	textprotoConn, err := textproto.Dial(network, address)
	if err != nil {
		return nil, err
	}

	conn := Conn{textprotoConn, ""}
	_, message, err := conn.ReadCodeLine(200)
	if err != nil {
		return nil, err
	}
	conn.message = message
	return &conn, nil
}
开发者ID:yansal,项目名称:nntp,代码行数:14,代码来源:nntp.go


注:本文中的net/textproto.Dial函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。