Beispiel #1
0
        /// <summary>
        /// Send a message to the peer node.
        /// </summary>
        /// <param name="data">Data to send to the peer node.</param>
        /// <returns>True if successful.</returns>
        public bool Send(byte[] data)
        {
            if (_ClusterClient != null)
            {
                if (_ClusterClient.Connected)
                {
                    return(_ClusterClient.Send(data));
                }
            }
            else if (String.IsNullOrEmpty(_CurrPeerIpPort))
            {
                if (Debug)
                {
                    Console.WriteLine("No peer connected");
                }
                return(false);
            }
            else if (_ClusterServer != null)
            {
                if (_ClusterServer.IsConnected(_CurrPeerIpPort))
                {
                    return(_ClusterServer.Send(_CurrPeerIpPort, data));
                }
            }

            if (Debug)
            {
                Console.WriteLine("Neither server or client are healthy");
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Send a message to the peer using a stream.
        /// </summary>
        /// <param name="metadata">Dictionary containing metadata.</param>
        /// <param name="contentLength">The amount of data to read from the stream.</param>
        /// <param name="stream">The stream containing the data.</param>
        /// <returns>True if successful.</returns>
        public bool Send(Dictionary <object, object> metadata, long contentLength, Stream stream)
        {
            if (contentLength < 0)
            {
                throw new ArgumentException("Content length must be zero or greater.");
            }
            if (stream == null || !stream.CanRead)
            {
                throw new ArgumentException("Cannot read from supplied stream.");
            }

            if (_ClusterClient != null)
            {
                if (_ClusterClient.Connected)
                {
                    return(_ClusterClient.Send(metadata, contentLength, stream));
                }
            }
            else if (String.IsNullOrEmpty(_CurrPeerIpPort))
            {
                Logger?.Invoke("[ClusterNode] No peer connected");
                return(false);
            }
            else if (_ClusterServer != null)
            {
                if (_ClusterServer.IsConnected(_CurrPeerIpPort))
                {
                    return(_ClusterServer.Send(_CurrPeerIpPort, metadata, contentLength, stream));
                }
            }

            Logger?.Invoke("[ClusterNode] Neither server or client are healthy");
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Send a message to the peer node using a stream.
        /// </summary>
        /// <param name="contentLength">The amount of data to read from the stream.</param>
        /// <param name="stream">The stream containing the data.</param>
        /// <returns>True if successful.</returns>
        public async Task <bool> Send(long contentLength, Stream stream)
        {
            if (contentLength < 0)
            {
                throw new ArgumentException("Content length must be zero or greater.");
            }
            if (stream == null || !stream.CanRead)
            {
                throw new ArgumentException("Cannot read from supplied stream.");
            }

            if (_ClusterClient != null)
            {
                if (_ClusterClient.Connected)
                {
                    return(await _ClusterClient.Send(contentLength, stream));
                }
            }
            else if (String.IsNullOrEmpty(_CurrPeerIpPort))
            {
                if (Debug)
                {
                    Log("No peer connected");
                }
                return(false);
            }
            else if (_ClusterServer != null)
            {
                if (_ClusterServer.IsConnected(_CurrPeerIpPort))
                {
                    return(await _ClusterServer.Send(_CurrPeerIpPort, contentLength, stream));
                }
            }

            if (Debug)
            {
                Log("Neither server or client are healthy");
            }
            return(false);
        }