示例#1
0
        public TcpWorker(IServiceProvider provider, MessagePipeInterprocessTcpOptions options, IAsyncPublisher <IInterprocessKey, IInterprocessValue> publisher)
        {
            this.provider = provider;
            this.cancellationTokenSource = new CancellationTokenSource();
            this.options   = options;
            this.publisher = publisher;

            this.server = new Lazy <SocketTcpServer>(() =>
            {
                return(SocketTcpServer.Listen(options.Host, options.Port));
            });

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

#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

            if (options.HostAsServer != null && options.HostAsServer.Value)
            {
                StartReceiver();
            }
        }
示例#2
0
        /// <summary>
        /// create TCP unix domain socket server and listen
        /// </summary>
        /// <param name="domainSocketPath">path to unix domain socket</param>
        /// <param name="recvBufferSize">socket's receive buffer size</param>
        /// <param name="sendBufferSize">socket's send buffer size</param>
        /// <exception cref="SocketException">unix domain socket not supported or socket already exists</exception>
        /// <returns>TCP unix domain socket server</returns>
        public static SocketTcpServer ListenUds(string domainSocketPath, int?sendBufferSize = null, int?recvBufferSize = null)
        {
            var server = new SocketTcpServer(AddressFamily.Unix, ProtocolType.IP, sendBufferSize, recvBufferSize);

            server.socket.Bind(new UnixDomainSocketEndPoint(domainSocketPath));
            server.socket.Listen(MaxConnections);
            return(server);
        }
示例#3
0
        public static SocketTcpServer Listen(string host, int port)
        {
            var ip     = new IPEndPoint(IPAddress.Parse(host), port);
            var server = new SocketTcpServer(ip.AddressFamily, ProtocolType.Tcp, null, null);

            server.socket.Bind(ip);
            server.socket.Listen(MaxConnections);
            return(server);
        }