当前位置: 首页>>代码示例>>C#>>正文


C# SendReceiveOptions类代码示例

本文整理汇总了C#中SendReceiveOptions的典型用法代码示例。如果您正苦于以下问题:C# SendReceiveOptions类的具体用法?C# SendReceiveOptions怎么用?C# SendReceiveOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SendReceiveOptions类属于命名空间,在下文中一共展示了SendReceiveOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BluetoothConnection

        /// <summary>
        /// Bluetooth connection constructor
        /// </summary>
        private BluetoothConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, BluetoothClient btClient)
            : base(connectionInfo, defaultSendReceiveOptions)
        {
            if (btClient != null)
                this.btClient = btClient;

            dataBuffer = new byte[NetworkComms.InitialReceiveBufferSizeBytes];
        }
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:11,代码来源:BluetoothConnection.cs

示例2: UDPConnectionListener

        /// <summary>
        /// Create a new instance of a UDP listener
        /// </summary>
        /// <param name="sendReceiveOptions">The SendReceiveOptions to use with incoming data on this listener</param>
        /// <param name="applicationLayerProtocol">If enabled NetworkComms.Net uses a custom 
        /// application layer protocol to provide useful features such as inline serialisation, 
        /// transparent packet transmission, remote peer handshake and information etc. We strongly 
        /// recommend you enable the NetworkComms.Net application layer protocol.</param>
        /// <param name="udpOptions">The UDPOptions to use with this listener</param>
        /// <param name="allowDiscoverable">Determines if the newly created <see cref="ConnectionListenerBase"/> will be discoverable if <see cref="Tools.PeerDiscovery"/> is enabled.</param>
        public UDPConnectionListener(SendReceiveOptions sendReceiveOptions,
            ApplicationLayerProtocolStatus applicationLayerProtocol, 
            UDPOptions udpOptions, bool allowDiscoverable = false)
            :base(ConnectionType.UDP, sendReceiveOptions, applicationLayerProtocol, allowDiscoverable)
        {
            if (applicationLayerProtocol == ApplicationLayerProtocolStatus.Disabled && udpOptions != UDPOptions.None)
                throw new ArgumentException("If the application layer protocol has been disabled the provided UDPOptions can only be UDPOptions.None.");

            UDPOptions = udpOptions;
        }
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:20,代码来源:UDPConnectionListener.cs

示例3: XRecv

        protected override bool XRecv(SendReceiveOptions flags, out Msg msg)
        {
            //  Deallocate old content of the message.

            msg = null;
            if (m_pipe == null || (msg = m_pipe.Read ()) == null)
            {
                return false;
            }
            return true;
        }
开发者ID:GianniBortoloBossini,项目名称:netmq,代码行数:11,代码来源:Pair.cs

示例4: GetConnection

        /// <summary>
        /// Create a TCP connection with the provided connectionInfo and sets the connection default SendReceiveOptions. If there is an existing connection that is returned instead.
        /// If a new connection is created it will be registered with NetworkComms and can be retrieved using <see cref="NetworkComms.GetExistingConnection(ConnectionInfo)"/> and overrides.
        /// </summary>
        /// <param name="connectionInfo">ConnectionInfo to be used to create connection</param>
        /// <param name="defaultSendReceiveOptions">The SendReceiveOptions which will be set as this connections defaults</param>
        /// <param name="establishIfRequired">If true will establish the TCP connection with the remote end point before returning</param>
        /// <returns>Returns a <see cref="TCPConnection"/></returns>
        public static TCPConnection GetConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, bool establishIfRequired = true)
        {
            //Added conditional compilation so that GetConnection method usage is not ambiguous. 
#if WINDOWS_PHONE || NETFX_CORE
            StreamSocket socket = null;
            return GetConnection(connectionInfo, defaultSendReceiveOptions, socket, establishIfRequired);
#else
            TcpClient tcpClient = null;
            return GetConnection(connectionInfo, defaultSendReceiveOptions, tcpClient, establishIfRequired);
#endif
        }
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:19,代码来源:TCPConnectionStatic.cs

示例5: Receive

        public void Receive(ref Msg msg, SendReceiveOptions options)
        {
            LastOptions = options;

            byte[] bytes = m_frames.Dequeue();

            msg.InitGC(bytes, bytes.Length);

            if (m_frames.Count != 0)
                msg.SetFlags(MsgFlags.More);
        }
开发者ID:hdxhan,项目名称:netmq,代码行数:11,代码来源:ReceivingSocketExtensionsTests.cs

示例6: Send

        public static void Send([NotNull] this IOutgoingSocket socket, [NotNull] byte[] data, int length, SendReceiveOptions options)
        {
            var msg = new Msg();
            msg.InitPool(length);

            Buffer.BlockCopy(data, 0, msg.Data, 0, length);

            socket.Send(ref msg, options);

            msg.Close();
        }
开发者ID:Robin--,项目名称:netmq,代码行数:11,代码来源:OutgoingSocketExtensions.cs

示例7: Connection

        /// <summary>
        /// Create a new connection object
        /// </summary>
        /// <param name="connectionInfo">ConnectionInfo corresponding to the new connection</param>
        /// <param name="defaultSendReceiveOptions">The SendReceiveOptions which should be used as connection defaults</param>
        protected Connection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions)
        {
            //If the application layer protocol is disabled the serialiser must be NullSerializer
            //and no data processors are allowed.
            if (connectionInfo.ApplicationLayerProtocol == ApplicationLayerProtocolStatus.Disabled)
            {
                if (defaultSendReceiveOptions.Options.ContainsKey("ReceiveConfirmationRequired"))
                    throw new ArgumentException("Attempted to create an unmanaged connection when the provided send receive" +
                        " options specified the ReceiveConfirmationRequired option. Please provide compatible send receive options in order to successfully" +
                        " instantiate this unmanaged connection.", "defaultSendReceiveOptions");

                if (defaultSendReceiveOptions.DataSerializer != DPSManager.GetDataSerializer<NullSerializer>())
                    throw new ArgumentException("Attempted to create an unmanaged connection when the provided send receive" +
                        " options serialiser was not NullSerializer. Please provide compatible send receive options in order to successfully" +
                        " instantiate this unmanaged connection.", "defaultSendReceiveOptions");

                if (defaultSendReceiveOptions.DataProcessors.Count > 0)
                    throw new ArgumentException("Attempted to create an unmanaged connection when the provided send receive" +
                        " options contains data processors. Data processors may not be used with unmanaged connections." +
                        " Please provide compatible send receive options in order to successfully instantiate this unmanaged connection.", "defaultSendReceiveOptions");
            }

            SendTimesMSPerKBCache = new CommsMath();            
            packetBuilder = new PacketBuilder();

            //Initialise the sequence counter using the global value
            //Subsequent values on this connection are guaranteed to be sequential
            packetSequenceCounter = Interlocked.Increment(ref NetworkComms.totalPacketSendCount);

            ConnectionInfo = connectionInfo;

            if (defaultSendReceiveOptions != null)
                ConnectionDefaultSendReceiveOptions = defaultSendReceiveOptions;
            else
                ConnectionDefaultSendReceiveOptions = NetworkComms.DefaultSendReceiveOptions;

            //Add any listener specific packet handlers if required
            if (connectionInfo.ConnectionListener != null)
                connectionInfo.ConnectionListener.AddListenerPacketHandlersToConnection(this);

            if (NetworkComms.commsShutdown) throw new ConnectionSetupException("Attempting to create new connection after global NetworkComms.Net shutdown has been initiated.");

            if (ConnectionInfo.ConnectionType == ConnectionType.Undefined || ConnectionInfo.RemoteEndPoint == null)
                throw new ConnectionSetupException("ConnectionType and RemoteEndPoint must be defined within provided ConnectionInfo.");

            //If a connection already exists with this info then we can throw an exception here to prevent duplicates
            if (NetworkComms.ConnectionExists(connectionInfo.RemoteEndPoint, connectionInfo.LocalEndPoint, connectionInfo.ConnectionType, connectionInfo.ApplicationLayerProtocol))
                throw new ConnectionSetupException("A " + connectionInfo.ConnectionType.ToString() + " connection already exists with info " + connectionInfo);

            //We add a reference in the constructor to ensure any duplicate connection problems are picked up here
            NetworkComms.AddConnectionReferenceByRemoteEndPoint(this);
        }
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:57,代码来源:ConnectionCreate.cs

示例8: PriorityQueueItem

        /// <summary>
        /// Initialise a new PriorityQueueItem
        /// </summary>
        /// <param name="priority"></param>
        /// <param name="connection"></param>
        /// <param name="packetHeader"></param>
        /// <param name="dataStream"></param>
        /// <param name="sendReceiveOptions"></param>
        public PriorityQueueItem(QueueItemPriority priority, Connection connection, PacketHeader packetHeader, MemoryStream dataStream, SendReceiveOptions sendReceiveOptions)
        {
            if (connection == null) throw new ArgumentNullException("connection", "Provided Connection parameter cannot be null.");
            if (packetHeader == null) throw new ArgumentNullException("packetHeader", "Provided PacketHeader parameter cannot be null.");
            if (dataStream == null) throw new ArgumentNullException("dataStream", "Provided MemoryStream parameter cannot be null.");
            if (sendReceiveOptions == null) throw new ArgumentNullException("sendReceiveOptions", "Provided sendReceiveOptions cannot be null.");

            this.Priority = priority;
            this.Connection = connection;
            this.PacketHeader = packetHeader;
            this.DataStream = dataStream;
            this.SendReceiveOptions = sendReceiveOptions;
        }
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:21,代码来源:PriorityQueueItem.cs

示例9: GetConnection

        /// <summary>
        /// Internal <see cref="BluetoothConnection"/> creation which hides the necessary internal calls
        /// </summary>
        /// <param name="connectionInfo">ConnectionInfo to be used to create connection</param>
        /// <param name="defaultSendReceiveOptions">Connection default SendReceiveOptions</param>
        /// <param name="btClient">If this is an incoming connection we will already have access to the btClient, otherwise use null</param>
        /// <param name="establishIfRequired">Establish during create if true</param>
        /// <returns>An existing connection or a new one</returns>
        internal static BluetoothConnection GetConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, BluetoothClient btClient, bool establishIfRequired = true)
        {
            connectionInfo.ConnectionType = ConnectionType.Bluetooth;

            //If we have a tcpClient at this stage we must be server side
            if (btClient != null) connectionInfo.ServerSide = true;

            bool newConnection = false;
            BluetoothConnection connection;

            lock (NetworkComms.globalDictAndDelegateLocker)
            {
                List<Connection> existingConnections = NetworkComms.GetExistingConnection(connectionInfo.RemoteEndPoint, connectionInfo.LocalEndPoint, connectionInfo.ConnectionType, connectionInfo.ApplicationLayerProtocol);

                //Check to see if a connection already exists, if it does return that connection, if not return a new one
                if (existingConnections.Count > 0)
                {
                    if (NetworkComms.LoggingEnabled)
                        NetworkComms.Logger.Trace("Attempted to create new BluetoothConnection to connectionInfo='" + connectionInfo + "' but there is an existing connection. Existing connection will be returned instead.");

                    establishIfRequired = false;
                    connection = (BluetoothConnection)existingConnections[0];
                }
                else
                {
                    if (NetworkComms.LoggingEnabled)
                        NetworkComms.Logger.Trace("Creating new BluetoothConnection to connectionInfo='" + connectionInfo + "'." + (establishIfRequired ? " Connection will be established." : " Connection will not be established."));

                    if (connectionInfo.ConnectionState == ConnectionState.Establishing)
                        throw new ConnectionSetupException("Connection state for connection " + connectionInfo + " is marked as establishing. This should only be the case here due to a bug.");

                    //If an existing connection does not exist but the info we are using suggests it should we need to reset the info
                    //so that it can be reused correctly. This case generally happens when using NetworkComms.Net in the format 
                    //TCPConnection.GetConnection(info).SendObject(packetType, objToSend);
                    if (connectionInfo.ConnectionState == ConnectionState.Established || connectionInfo.ConnectionState == ConnectionState.Shutdown)
                        connectionInfo.ResetConnectionInfo();

                    //We add a reference to networkComms for this connection within the constructor
                    connection = new BluetoothConnection(connectionInfo, defaultSendReceiveOptions, btClient);
     
                    newConnection = true;
                }
            }

            if (newConnection && establishIfRequired) connection.EstablishConnection();
            else if (!newConnection) connection.WaitForConnectionEstablish(NetworkComms.ConnectionEstablishTimeoutMS);

            if (!NetworkComms.commsShutdown) TriggerConnectionKeepAliveThread();

            return connection;
        }
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:59,代码来源:BluetoothConnectionStatic.cs

示例10: Receive

        public static byte[] Receive([NotNull] this IReceivingSocket socket, SendReceiveOptions options, out bool hasMore)
        {
            var msg = new Msg();
            msg.InitEmpty();

            socket.Receive(ref msg, options);

            var data = msg.CloneData();

            hasMore = msg.HasMore;

            msg.Close();

            return data;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:15,代码来源:ReceivingSocketExtensions.cs

示例11: Send

        /// <summary>
        /// Transmit a string-message of data over this socket. The string will be encoded into bytes using the specified Encoding.
        /// </summary>
        /// <param name="socket">the IOutgoingSocket to transmit on</param>
        /// <param name="message">a string containing the message to send</param>
        /// <param name="encoding">the Encoding to use when converting the message-string into bytes</param>
        /// <param name="options">use this to specify which of the DontWait and SendMore flags to set</param>
        public static void Send([NotNull] this IOutgoingSocket socket, [NotNull] string message, [NotNull] Encoding encoding, SendReceiveOptions options)
        {
            var msg = new Msg();

            // Count the number of bytes required to encode the string.
            // Note that non-ASCII strings may not have an equal number of characters
            // and bytes. The encoding must be queried for this answer.
            // With this number, request a buffer from the pool.
            msg.InitPool(encoding.GetByteCount(message));

            // Encode the string into the buffer
            encoding.GetBytes(message, 0, message.Length, msg.Data, 0);

            socket.Send(ref msg, options);

            msg.Close();
        }
开发者ID:wangkai2014,项目名称:netmq,代码行数:24,代码来源:OutgoingSocketExtensions.cs

示例12: TCPConnection

        private TCPConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, TcpClient tcpClient, SSLOptions sslOptions)
#endif
            : base(connectionInfo, defaultSendReceiveOptions)
        {
            if (connectionInfo.ConnectionType != ConnectionType.TCP)
                throw new ArgumentException("Provided connectionType must be TCP.", "connectionInfo");

            dataBuffer = new byte[NetworkComms.InitialReceiveBufferSizeBytes];

            //We don't guarantee that the tcpClient has been created yet
#if WINDOWS_PHONE || NETFX_CORE
            if (socket != null) this.socket = socket;
#else
            if (tcpClient != null) this.tcpClient = tcpClient;
            this.SSLOptions = sslOptions;
#endif
        }
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:17,代码来源:TCPConnection.cs

示例13: XSend

        protected override bool XSend(Msg msg, SendReceiveOptions flags)
        {
            if (m_pipe == null || !m_pipe.Write (msg))
            {
                return false;
            }

            if ((flags & SendReceiveOptions.SendMore) == 0)
                m_pipe.Flush ();

            //  Detach the original message from the data buffer.
            return true;
        }
开发者ID:GianniBortoloBossini,项目名称:netmq,代码行数:13,代码来源:Pair.cs

示例14: ReceiveInternal

 protected internal override Msg ReceiveInternal(SendReceiveOptions options, out bool hasMore)
 {
     throw new NotSupportedException("Push socket doesn't support receiving");
 }
开发者ID:GianniBortoloBossini,项目名称:netmq,代码行数:4,代码来源:PushSocket.cs

示例15: ReceiveString

        public static string ReceiveString([NotNull] this IReceivingSocket socket, [NotNull] Encoding encoding, SendReceiveOptions options, out bool hasMore)
        {
            if (encoding == null)
                throw new ArgumentNullException("encoding");

            var msg = new Msg();
            msg.InitEmpty();

            socket.Receive(ref msg, options);

            hasMore = msg.HasMore;

            string data = msg.Size > 0
                ? encoding.GetString(msg.Data, msg.Offset, msg.Size)
                : string.Empty;

            msg.Close();
            return data;
        }
开发者ID:hdxhan,项目名称:netmq,代码行数:19,代码来源:ReceivingSocketExtensions.cs


注:本文中的SendReceiveOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。