Click here to Skip to main content
15,898,942 members
Home / Discussions / C#
   

C#

 
GeneralRe: DateTime.Now Pin
DaveyM6912-Jun-08 0:39
professionalDaveyM6912-Jun-08 0:39 
GeneralRe: DateTime.Now Pin
George_George12-Jun-08 1:29
George_George12-Jun-08 1:29 
GeneralRe: DateTime.Now Pin
Guffa11-Jun-08 2:19
Guffa11-Jun-08 2:19 
GeneralRe: DateTime.Now Pin
George_George11-Jun-08 1:28
George_George11-Jun-08 1:28 
GeneralRe: DateTime.Now Pin
George_George11-Jun-08 1:26
George_George11-Jun-08 1:26 
AnswerRe: DateTime.Now Pin
#realJSOP10-Jun-08 6:29
professional#realJSOP10-Jun-08 6:29 
GeneralRe: DateTime.Now Pin
George_George11-Jun-08 1:40
George_George11-Jun-08 1:40 
Questionasynchronous function callback Pin
George_George9-Jun-08 17:14
George_George9-Jun-08 17:14 
Hello everyone,


Here is my code for an HttpService. My question is, if there is no coming client request, both (1) and (2) wil be blocked and when there is a coming request,

1. the the callback function provided as the 1st parameter of the BeginGetContext function will be called;
2. and also for the handle wait on (result.AsyncWaitHandle.WaitOne()) will be signalled.

Are there any sequences for (1) and (2)? i.e. for asynchronous call, signal is set before callback is called or vice versa?

public class TestHttpServer
{
    // listening HTTP port
    private int _Port = 0;

    // internal wrapped HTTP listener
    private HttpListener _Server = new HttpListener();

    private Service1 _manager;

    public TestHttpServer (Service1 manager)
    {
        _manager = manager;
    }

    public int ListenPort
    {
        get
        {
            return _Port;
        }
        set
        {
            _Port = value;
        }
    }

    public void StartListen()
    {
        try
        {
            IAsyncResult result;
            _Server.Prefixes.Add(String.Format("http://+:{0}/", 9099));
            _Server.Start();
            while (true)
            {
                result = _Server.BeginGetContext(new AsyncCallback(this.HttpCallback), _Server);
                result.AsyncWaitHandle.WaitOne();
            }
        }
        // any exceptions are not expected
        // catch InvalidOperationException during service stop
        // [System.InvalidOperationException] = {"Please call the Start() method before calling this method."}
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public void Stop(bool isTerminate)
    {
        _Server.Stop();
    }

    // callback function when there is HTTP request received
    private void HttpCallback(IAsyncResult result)
    {
        HttpListenerContext context = _Server.EndGetContext(result);
        HandleRequest(context);
    }

    // find matched URL HTTP request handler and invoke related handler
    private void HandleRequest(HttpListenerContext context)
    {
        string matchUrl = context.Request.Url.AbsolutePath.Trim().ToLower();

        context.Response.StatusCode = 200;
        context.Response.StatusDescription = "OK";
        context.Response.Close();
    }
}



thanks in advance,
George
AnswerRe: asynchronous function callback Pin
N a v a n e e t h11-Jun-08 16:22
N a v a n e e t h11-Jun-08 16:22 
GeneralRe: asynchronous function callback Pin
George_George11-Jun-08 16:34
George_George11-Jun-08 16:34 
QuestionWill Using Console.Beep(); Too Much Damage Your Computer? Pin
qszwdxefc9-Jun-08 16:59
qszwdxefc9-Jun-08 16:59 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Christian Graus9-Jun-08 17:16
protectorChristian Graus9-Jun-08 17:16 
JokeRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
PIEBALDconsult9-Jun-08 17:26
mvePIEBALDconsult9-Jun-08 17:26 
GeneralRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
MarkB7779-Jun-08 17:49
MarkB7779-Jun-08 17:49 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Joe Woodbury9-Jun-08 19:30
professionalJoe Woodbury9-Jun-08 19:30 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Ashfield9-Jun-08 21:24
Ashfield9-Jun-08 21:24 
QuestionBind a Datatable With an Hyperlink Column To a GridView Pin
HatakeKaKaShi9-Jun-08 16:51
HatakeKaKaShi9-Jun-08 16:51 
QuestionBinary Reader Scanning for string Pin
Jammer9-Jun-08 15:12
Jammer9-Jun-08 15:12 
AnswerRe: Binary Reader Scanning for string Pin
Insincere Dave9-Jun-08 17:21
Insincere Dave9-Jun-08 17:21 
GeneralRe: Binary Reader Scanning for string Pin
Jammer10-Jun-08 3:22
Jammer10-Jun-08 3:22 
AnswerRe: Binary Reader Scanning for string Pin
Guffa10-Jun-08 12:02
Guffa10-Jun-08 12:02 
GeneralRe: Binary Reader Scanning for string Pin
Jammer10-Jun-08 12:17
Jammer10-Jun-08 12:17 
GeneralRe: Binary Reader Scanning for string Pin
Jammer10-Jun-08 13:36
Jammer10-Jun-08 13:36 
GeneralRe: Binary Reader Scanning for string Pin
Guffa10-Jun-08 20:32
Guffa10-Jun-08 20:32 
GeneralRe: Binary Reader Scanning for string Pin
Jammer11-Jun-08 9:21
Jammer11-Jun-08 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.