private void SendHeartBeatThread(object sender) { if (Connected) { //IsMaster = ConnectionInstance.IsMaster(); if (!ConnectionInstance.SendHeartBeat()) { LOG.Error(string.Format("心跳检测错误")); //连接错误 ServerEventArg arg = new ServerEventArg("Unknown", ServerEventType.Disconnected); OnConnectFaultHander?.BeginInvoke(arg, null, null); } } }
public void StartConnect() { if (Connected) { return; } // 创建 switch (HostType) { case HostConnectionType.Machine: ConnectionInstance = MachineProxy.Create(RemoteHostAddress); break; case HostConnectionType.Process: ConnectionInstance = ProcessProxy.Create(RemoteHostAddress); break; case HostConnectionType.Resource: ConnectionInstance = ResourceProxy.Create(RemoteHostAddress); break; case HostConnectionType.Partner: ConnectionInstance = PartnerProxy.Create(RemoteHostAddress); break; case HostConnectionType.Admin: ConnectionInstance = AdminProxy.Create(RemoteHostAddress); break; default: throw new NotSupportedException(); } // 连接 ConnectionInstance?.Connect(); if (Connected) { //连接事件 ServerEventArg arg = new ServerEventArg("Unknown", ServerEventType.Connected); LOG.Info($"启动{HostType.ToString()}对方端口{RemoteHostAddress}成功"); OnConnectedHander?.BeginInvoke(arg, null, null); //启动心跳 //StartHeartbeat(); } else { //连接失败 ServerEventArg arg = new ServerEventArg("Unknown", ServerEventType.Fault); LOG.Debug($"启动{HostType.ToString()}对方端口{RemoteHostAddress}失败"); OnConnectFaultHander?.BeginInvoke(arg, null, null); ConnectionInstance = null; } }