示例#1
0
        /// <summary>
        ///   This method gets called when the remote service provider closes the
        ///   connection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDisconnected(Object sender, TcpSocketNotificationEventArgs e)
        {
            lock (_connections)
            {
                if (ServiceHost.Instance.DebugConnections)
                {
                    Console.WriteLine(String.Format("Lost connection #{0} to remote service.",
                                                    e.Socket.ChannelId));
                }

                Connection connection;
                if (!_connections.TryGetValue(e.Socket.ChannelId, out connection))
                {
                    Console.WriteLine(String.Format("Error: Failed to remove connection #{0}.",
                                                    e.Socket.ChannelId));
                    return;
                }
                lock (Sockets)
                {
                    Sockets.Remove(e.Socket);
                }
                --_connectedServicesCount;

                var handler = DisconnectedRemoteService;
                if (handler != null)
                {
                    handler(this, new DisconnectedRemoteServiceArgs(
                                connection.HostGuid, connection.ServiceGuid));
                }

                _connections.Remove(e.Socket.ChannelId);
            }
        }
示例#2
0
 /// <summary>
 ///   The attempt to connect to the remote service has failed for whatever
 ///   reason.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnConnectFailed(Object sender, TcpSocketNotificationEventArgs e)
 {
     // This may happen if the remote service died right after broadcasting
     // its address.
     /// ToDo: Print out some log message.
     Console.WriteLine(String.Format("Warning: Connection #{0} failed.",
                                     e.Socket.ChannelId));
 }
示例#3
0
        /// <summary>
        ///   This method gets called when the connection to a service has been
        ///   established.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        ///   The method sends the initial handshake message, which is used to
        ///   validate that the two services actually match (using their
        ///   serviceTypeId, serviceGuids and hostGuids) and to agree on a
        ///   protocol version supported by both ends. The answer will be received
        ///   using onReceiveHandshake. If the remote service rejects the connect
        ///   attempt it will close the connection and thus result in a call to
        ///   onDisconnected.
        /// </remarks>
        private void OnConnected(Object sender, TcpSocketNotificationEventArgs e)
        {
            e.Socket.MessageReceived += OnReceiveHandshake;
            if (!IsProvider)
            {
                SendHandshake(e.Socket);
            }

            if (ServiceHost.Instance.DebugConnections)
            {
                Console.WriteLine(String.Format("Established connection #{0} to remote service.",
                                                e.Socket.ChannelId));
            }
        }
示例#4
0
 private void OnClientDisconnected(object sender, TcpSocketNotificationEventArgs e)
 {
 }