Esempio n. 1
0
func NewRemotingClient(conn *net.TCPConn,
	packetDispatcher func(remoteClient *RemotingClient, p *packet.Packet),
	rc *turbo.RemotingConfig) *RemotingClient {

	remoteSession := session.NewSession(conn, rc)

	//创建一个remotingcleint
	remotingClient := &RemotingClient{
		heartbeat:        0,
		conn:             conn,
		packetDispatcher: packetDispatcher,
		remoteSession:    remoteSession,
		rc:               rc}

	return remotingClient
}
Esempio n. 2
0
//重连
func (self *RemotingClient) reconnect() (bool, error) {

	conn, err := net.DialTCP("tcp4", nil, self.conn.RemoteAddr().(*net.TCPAddr))
	if nil != err {
		log.Error("RemotingClient|RECONNECT|%s|FAIL|%s\n", self.RemoteAddr(), err)
		return false, err
	}

	//重新设置conn
	self.conn = conn
	//创建session
	self.remoteSession = session.NewSession(self.conn, self.rc)

	//再次启动remoteClient
	self.Start()
	return true, nil
}