/// <summary>
 /// Indicates that a request was received and responds to it.
 /// </summary>
 /// <remarks>On invalid request you would call: <see cref="IResponder{TResponse}.Reject(string)"/>.</remarks>
 public void OnRequest(string path, string request, IResponder <string> responder)
 {
     if (request == "Hello?")        // message to the filter to obtain the session ID
     {
         responder.Respond("Yes");
     }
     else
     {
         WriteLine($"Received request: '{request}'.");
         responder.Respond(DateTime.UtcNow.ToLongTimeString());
     }
 }
        /// <summary>
        /// this method is triggered by the listen function. it's main job is to saftly call
        /// the respond mehtod if it exists.
        /// </summary>
        /// <param name="dataRecived">
        /// this is a string represention of the
        /// </param>
        /// <param name="endpoint">
        /// Details about the other side of the coversation
        /// </param>
        private void Responce(string dataRecived, ref IPEndPoint endpoint)
        {
            //create a client to send the data back to
            //System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient(endpoint.Port, endpoint.AddressFamily);

            // create a lock on this so there are no collisons or erros
            lock (ResponceLock)
            {
                // call the responder method to send the new information
                if (responder != null)
                {
                    responder.Respond(dataRecived, this.EndpointClient, ref endpoint);
                }
                else
                {
                    // Code to echo back a responce
                    byte[] data = Encoding.Unicode.GetBytes(dataRecived);
                    this.EndpointClient.SendAsync(data, data.Length, endpoint);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult"/> class.
        /// </summary>
        /// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
        public override void ExecuteResult(ControllerContext context)
        {
            Invariant.IsNotNull(context, "context");

            IHasResponders controller = context.Controller as IHasResponders;

            if (controller == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Controller \"{0}\" does not support respond with.", context.RouteData.ControllerName()));
            }

            IResponder responder = controller.Responders.FindMatching(context);

            if (responder == null)
            {
                new HttpStatusCodeResult((int)HttpStatusCode.UnsupportedMediaType).ExecuteResult(context);
                return;
            }

            responderContext.ControllerContext = context;

            responder.Respond(responderContext);
        }
 /// <summary>
 /// Indicates that a request was received and responds to it.
 /// </summary>
 /// <remarks>On invalid request you would call: <see cref="IResponder{TResponse}.Reject(string)"/>.</remarks>
 public void OnRequest(string path, string request, IResponder <string> responder)
 {
     WriteLine($"Received request: '{request}'.");
     responder.Respond(DateTime.UtcNow.ToLongTimeString());
 }