本文整理汇总了C#中System.Net.HttpListener.BeginGetContext方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListener.BeginGetContext方法的具体用法?C# HttpListener.BeginGetContext怎么用?C# HttpListener.BeginGetContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpListener
的用法示例。
在下文中一共展示了HttpListener.BeginGetContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start(string bindUrl)
{
Ensure.NotNull(bindUrl, nameof(bindUrl));
_httpListener = new HttpListener { IgnoreWriteExceptions = false };
_httpListener.Prefixes.Add(bindUrl);
_httpListener.Start();
AsyncCallback acceptConnection = null;
acceptConnection = state =>
{
try
{
HttpListenerContext clientContext = _httpListener.EndGetContext(state);
Log.Info($"New Ecr connection from: {clientContext.Request.RemoteEndPoint}");
ProcessAsync(clientContext);
}
catch (Exception ex)
{
Log.Error(ex);
}
finally
{
_httpListener.BeginGetContext(acceptConnection, null);
}
};
_httpListener.BeginGetContext(acceptConnection, null);
RegisterActions();
}
示例2: Start
public void Start()
{
httpListener = new HttpListener();
httpListener.Prefixes.Add("http://localhost:" + this.ListenPort + "/");
httpListener.Start();
httpListener.BeginGetContext(this.OnNewRequest, null);
}
示例3: Sewers
public Sewers()
{
_listener = new HttpListener();
string prefix = "http://*:81/";
_listener.Prefixes.Add(prefix);
_messages = new Demonic("127.0.0.1");
_messages.setName("Black Temple");
_messages.setPort(11201);
_messages.addMethod("RESPONSE");
_messages.setCallback(onMessageRecieved);
_messages.init();
try
{
_listener.Start();
while (true)
{
System.Console.WriteLine("Listening");
IAsyncResult result = _listener.BeginGetContext(new AsyncCallback(ListenerCallback), _listener);
result.AsyncWaitHandle.WaitOne();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
}
示例4: ListenTo
/// <summary>
/// Starts the Authorisation listener to listen to the specified port.
/// </summary>
/// <param name="port"></param>
public void ListenTo(int port)
{
if (!HttpListener.IsSupported)
{
Debug.Write("AuthListener unsupported: Windows XP SP2 or Server 2003 is required");
throw new NotSupportedException("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
}
try
{
this._server = new HttpListener();
var prefix = String.Format("http://localhost:{0}/", port);
this._server.Prefixes.Add(prefix);
Debug.WriteLine("Prefix " + prefix + " added.");
// Start listening for client requests.
this._server.Start();
Debug.WriteLine("Waiting for a connection... ");
// Start waiting for a request
_server.BeginGetContext(new AsyncCallback(ListenerCallback), _server);
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
this.Stop();
}
}
示例5: Start
public void Start()
{
listener = new HttpListener();
string virtualDirectory = Configuration.VirtualDirectory;
if (virtualDirectory.EndsWith("/") == false)
virtualDirectory = virtualDirectory + "/";
listener.Prefixes.Add("http://+:" + Configuration.Port + virtualDirectory);
switch (Configuration.AnonymousUserAccessMode)
{
case AnonymousUserAccessMode.None:
listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;
break;
case AnonymousUserAccessMode.All:
break;
case AnonymousUserAccessMode.Get:
listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication |
AuthenticationSchemes.Anonymous;
listener.AuthenticationSchemeSelectorDelegate = request =>
{
return request.HttpMethod == "GET" || request.HttpMethod == "HEAD" ?
AuthenticationSchemes.Anonymous :
AuthenticationSchemes.IntegratedWindowsAuthentication;
};
break;
default:
throw new ArgumentException("Cannot understand access mode: " + Configuration.AnonymousUserAccessMode );
}
listener.Start();
listener.BeginGetContext(GetContext, null);
}
示例6: Main
private static void Main(string[] args)
{
XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net_server.config"));
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.Name = "Entry";
Database = new Database();
GameData = new XmlData();
InstanceId = Guid.NewGuid().ToString();
Console.CancelKeyPress += (sender, e) => e.Cancel = true;
if (RunPreCheck(port))
{
listener = new HttpListener();
listener.Prefixes.Add($"http://*:{port}/");
listener.Start();
listener.BeginGetContext(ListenerCallback, null);
Logger.Info($"Listening at port {port}...");
}
else
Logger.Error($"Port {port} is occupied");
while (Console.ReadKey(true).Key != ConsoleKey.Escape) ;
Logger.Info("Terminating...");
while (currentRequests.Count > 0) ;
listener?.Stop();
}
示例7: HttpServer
public HttpServer()
{
this.listener = new HttpListener();
listener.Prefixes.Add(URL + "/");
listener.Start();
listener.BeginGetContext(new AsyncCallback(ListenerCallback), null);
}
示例8: ServerModel
public ServerModel()
{
mListener = new HttpListener();
mListener.Prefixes.Add( "http://*:8181/" );
mListener.Start();
mListener.BeginGetContext( new AsyncCallback( ListenerCallback ), mListener );
}
示例9: Setup
public void Setup()
{
requestedUrl.Clear();
partialData = false;
int i;
for (i = 0; i < 1000; i++)
{
try
{
listener = new HttpListener();
listener.Prefixes.Add(string.Format(listenerURL, i));
listener.Start();
break;
}
catch
{
}
}
listener.BeginGetContext(GotContext, null);
rig = TestRig.CreateMultiFile();
connection = new HttpConnection(new Uri(string.Format(listenerURL, i)));
connection.Manager = rig.Manager;
id = new PeerId(new Peer("this is my id", connection.Uri), rig.Manager);
id.Connection = connection;
id.IsChoking = false;
id.AmInterested = true;
id.BitField.SetAll(true);
id.MaxPendingRequests = numberOfPieces;
requests = rig.Manager.PieceManager.Picker.PickPiece(id, new List<PeerId>(), numberOfPieces);
}
示例10: HttpServer
public HttpServer(string baseDirectory)
{
this.baseDirectory = baseDirectory;
var rnd = new Random();
for (int i = 0; i < 100; i++)
{
int port = rnd.Next(49152, 65536);
try
{
listener = new HttpListener();
listener.Prefixes.Add("http://localhost:" + port + "/");
listener.Start();
this.port = port;
listener.BeginGetContext(ListenerCallback, null);
return;
}
catch (Exception x)
{
listener.Close();
Debug.WriteLine("HttpListener.Start:\n" + x);
}
}
throw new ApplicationException("Failed to start HttpListener");
}
示例11: AsyncHttpServer
public AsyncHttpServer()
{
_listener = new HttpListener();
_listener.Prefixes.Add("http://+:80/");
_listener.Start();
_listener.BeginGetContext(GetContext, null);
}
示例12: DetergentHttpListener
public DetergentHttpListener(
string uriPrefix,
string applicationPath,
IDetergentHttpHandler detergentHttpHandler)
{
if (uriPrefix == null)
throw new ArgumentNullException("uriPrefix");
if (applicationPath == null)
throw new ArgumentNullException("applicationPath");
if (detergentHttpHandler == null) throw new ArgumentNullException("detergentHttpHandler");
this.uriPrefix = uriPrefix;
this.applicationPath = applicationPath;
this.detergentHttpHandler = detergentHttpHandler;
httpListener = new HttpListener();
applicationRootUrl = new Uri(new Uri(uriPrefix), applicationPath).ToString();
if (false == applicationRootUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase))
applicationRootUrl = applicationRootUrl + '/';
httpListener.Prefixes.Add(applicationRootUrl);
DumpDiagnostics();
httpListener.Start();
IAsyncResult result = httpListener.BeginGetContext(WebRequestCallback, httpListener);
}
示例13: Main
static HttpListener listener; // http server providing clipboard history selection
public static void Main (string[] args)
{
// make UI methods for clipboard access available
Application.Init ();
// setup http interface
listener = new HttpListener();
listener.Prefixes.Add("http://*:5544/");
listener.Start();
listener.BeginGetContext(ProcessRequest, null);
// initialize access to clipboard
clippy = Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", false));
// schedule polling of clipboard content
timer = new System.Timers.Timer(300);
timer.Elapsed += new System.Timers.ElapsedEventHandler(ReadClipboardUI);
timer.Start();
// just to prevent termination of the app
Application.Run();
// shutdown http interface
listener.Stop();
}
示例14: Run
protected void Run()
{
_listener = new HttpListener();
_listener.Prefixes.Add(Host);
_listener.Start();
_listener.BeginGetContext(GetContext, null);
}
示例15: Start
/// <summary>
/// 启动监听
/// </summary>
public static void Start(int port)
{
listener = new HttpListener();
listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
listener.Prefixes.Add(string.Format("http://*:{0}/", port));
listener.Start();
listener.BeginGetContext(new System.AsyncCallback(GetContextCallBack), listener);
}