diff --git a/cluster/cluster.go b/cluster/cluster.go index aa9470d..84b30eb 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -145,3 +145,8 @@ func GetRpcClient(nodeId int,serviceMethod string) ([]*rpc.Client,error) { func GetRpcServer() *rpc.Server{ return &cluster.rpcServer } + +func (slf *Cluster) IsNodeConnected (nodeId int) bool { + pClient := slf.GetRpcClient(nodeId) + return pClient!=nil && pClient.IsConnected() +} diff --git a/network/tcp_conn.go b/network/tcp_conn.go index 58b36cc..26c2318 100644 --- a/network/tcp_conn.go +++ b/network/tcp_conn.go @@ -111,3 +111,7 @@ func (tcpConn *TCPConn) ReadMsg() ([]byte, error) { func (tcpConn *TCPConn) WriteMsg(args ...[]byte) error { return tcpConn.msgParser.Write(tcpConn, args...) } + +func (tcpConn *TCPConn) IsConnected() bool { + return tcpConn.closeFlag == false +} \ No newline at end of file diff --git a/rpc/client.go b/rpc/client.go index c308f4e..fa9dc6f 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -219,3 +219,7 @@ func (slf *Client) Run(){ func (slf *Client) OnClose(){ } + +func (slf *Client) IsConnected() bool { + return slf.conn!=nil && slf.conn.IsConnected()==true +} \ No newline at end of file