コード例 #1
0
 protected virtual void DispatchDisconnected(ObjectDelivererProtocol delivererProtocol)
 {
     this.disconnected?.OnNext(new ConnectedData()
     {
         Target = delivererProtocol
     });
 }
コード例 #2
0
        public ValueTask SendToMessageAsync(T message, ObjectDelivererProtocol target)
        {
            if (this.deliveryBox == null)
            {
                return(default(ValueTask));
            }

            return(this.SendToAsync(this.deliveryBox.MakeSendBuffer(message), target));
        }
コード例 #3
0
        protected override void DispatchDisconnected(ObjectDelivererProtocol delivererProtocol)
        {
            base.DispatchDisconnected(delivererProtocol);

            if (this.AutoConnectAfterDisconnect)
            {
                this.StartConnect();
            }
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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();
            }
        }