protected virtual void DispatchDisconnected(ObjectDelivererProtocol delivererProtocol) { this.disconnected?.OnNext(new ConnectedData() { Target = delivererProtocol }); }
public ValueTask SendToMessageAsync(T message, ObjectDelivererProtocol target) { if (this.deliveryBox == null) { return(default(ValueTask)); } return(this.SendToAsync(this.deliveryBox.MakeSendBuffer(message), target)); }
protected override void DispatchDisconnected(ObjectDelivererProtocol delivererProtocol) { base.DispatchDisconnected(delivererProtocol); if (this.AutoConnectAfterDisconnect) { this.StartConnect(); } }
public ValueTask StartAsync(ObjectDelivererProtocol protocol, IPacketRule packetRule, IDeliveryBox <T>?deliveryBox = null) { if (protocol == null || packetRule == null) { return(default(ValueTask)); } this.currentProtocol = protocol; this.currentProtocol.SetPacketRule(packetRule); this.deliveryBox = deliveryBox; this.currentProtocol.Connected.Subscribe(x => { this.ConnectedList.Add(x.Target); this.connected.OnNext(x); }); this.currentProtocol.Disconnected.Subscribe(x => { this.ConnectedList.Remove(x.Target); this.disconnected.OnNext(x); }); this.currentProtocol.ReceiveData.Subscribe(x => { var data = new DeliverData <T>() { Sender = x.Sender, Buffer = x.Buffer, }; if (deliveryBox != null) { data.Message = deliveryBox.BufferToMessage(x.Buffer); } this.receiveData.OnNext(data); }); this.ConnectedList.Clear(); return(this.currentProtocol.StartAsync()); }
private async void ClientSocket_Disconnected(ObjectDelivererProtocol delivererProtocol) { if (delivererProtocol == null) { return; } if (delivererProtocol is ProtocolIPSocket protocolTcpIp) { lock (this.connectedSockets) { int foundIndex = this.connectedSockets.IndexOf(protocolTcpIp); if (foundIndex >= 0) { this.connectedSockets.RemoveAt(foundIndex); } } this.DispatchDisconnected(protocolTcpIp); await protocolTcpIp.DisposeAsync(); } }