示例#1
0
        /// <summary>
        ///   Send a message to the specified remote service.
        /// </summary>
        public void SendTo(ulong remoteServiceGuid, Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException();
            }

            /// ToDo: Which protocol version to use?

            lock (_connections)
            {
                foreach (var connection in _connections)
                {
                    if (connection.Value.ServiceGuid == remoteServiceGuid)
                    {
                        var stream = new Shift.Network.MessageStream(1);
                        stream.Write(message.MessageUid);
                        stream.Write(message, null, new Group());
                        connection.Value.Socket.Post(stream);
                        return;
                    }
                }
                Console.WriteLine("Warning: Attempt to send message to the remote service " +
                                  remoteServiceGuid + ", which does not exist.");
            }
        }
示例#2
0
        /// <summary>
        ///   Send a message to the remote service, which called the last service event.
        /// </summary>
        /// <remarks>
        ///   This is only valid from within a service event to reply to the
        ///   caller. Naturally this doesn't make sense from within another thread.
        /// </remarks>
        protected void Reply(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException();
            }
            var caller = Caller.Value;

            if (caller == null)
            {
                throw new InvalidOperationException();
            }
            /// ToDo: Which protocol version to use?
            var stream = new Shift.Network.MessageStream(1);

            stream.Write(message.MessageUid);
            stream.Write(message, null, new Group());
            caller.Socket.Post(stream);
        }
示例#3
0
        /// <summary>
        ///   Broadcasts a message to all connected remote services.
        /// </summary>
        public void Broadcast(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException();
            }
            /// ToDo: Which protocol version to use?
            var stream = new Shift.Network.MessageStream(1);

            stream.Write(message.MessageUid);
            stream.Write(message, null, new Group());
            lock (Sockets)
            {
                foreach (var socket in Sockets)
                {
                    socket.Post(stream);
                }
            }
        }