Пример #1
0
        public UdpWorker(MessagePipeInterprocessUdpOptions options, IAsyncPublisher <IInterprocessKey, IInterprocessValue> publisher)
        {
            this.cancellationTokenSource = new CancellationTokenSource();
            this.options   = options;
            this.publisher = publisher;

            this.server = new Lazy <SocketUdpServer>(() =>
            {
                return(SocketUdpServer.Bind(options.Port, 0x10000));
            });

            this.client = new Lazy <SocketUdpClient>(() =>
            {
                return(SocketUdpClient.Connect(options.Host, options.Port, 0x10000));
            });

#if !UNITY_2018_3_OR_NEWER
            this.channel = Channel.CreateUnbounded <byte[]>(new UnboundedChannelOptions()
            {
                SingleReader = true,
                SingleWriter = false,
                AllowSynchronousContinuations = true
            });
#else
            this.channel = Channel.CreateSingleConsumerUnbounded <byte[]>();
#endif
        }
Пример #2
0
        public static ReturnType AddMessagePipeUdpInterprocess(this IServiceCollection services, string host, int port, Action <MessagePipeInterprocessUdpOptions> configure)
        {
            var options = new MessagePipeInterprocessUdpOptions(host, port);

            configure(options);

            services.AddSingleton(options);
            services.Add(typeof(UdpWorker), options.InstanceLifetime);

#if !UNITY_2018_3_OR_NEWER
            services.Add(typeof(IDistributedPublisher <,>), typeof(UdpDistributedPublisher <,>), options.InstanceLifetime);
            services.Add(typeof(IDistributedSubscriber <,>), typeof(UdpDistributedSubscriber <,>), options.InstanceLifetime);
            return(services);
#else
            AddAsyncMessageBroker <IInterprocessKey, IInterprocessValue>(services, options);
            return(options);
#endif
        }