本文整理汇总了C#中HttpListener类的典型用法代码示例。如果您正苦于以下问题:C# HttpListener类的具体用法?C# HttpListener怎么用?C# HttpListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpListener类属于命名空间,在下文中一共展示了HttpListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPrefix
public static void AddPrefix(string uriPrefix, HttpListener httpListener)
{
lock (((ICollection) _ipToEndpoints).SyncRoot)
{
addPrefix (uriPrefix, httpListener);
}
}
示例2: AddPrefix
public static void AddPrefix(string prefix, HttpListener listener)
{
lock (_ipToEndpoints)
{
AddPrefixInternal(prefix, listener);
}
}
示例3: getEndPointListener
private static EndPointListener getEndPointListener (
IPAddress address, int port, HttpListener httpListener, bool secure)
{
Dictionary<int, EndPointListener> endpoints = null;
if (_ipToEndpoints.ContainsKey (address)) {
endpoints = _ipToEndpoints [address];
}
else {
endpoints = new Dictionary<int, EndPointListener> ();
_ipToEndpoints [address] = endpoints;
}
EndPointListener epListener = null;
if (endpoints.ContainsKey (port)) {
epListener = endpoints [port];
}
else {
epListener = new EndPointListener (
address,
port,
secure,
httpListener.CertificateFolderPath,
httpListener.DefaultCertificate);
endpoints [port] = epListener;
}
return epListener;
}
示例4: Awake
void Awake()
{
listener = new HttpListener();
listener.Prefixes.Add("http://*:7663/");
listener.Start();
listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
}
示例5: StartListener
static void StartListener()
{
listener = new HttpListener();
listener.Prefixes.Add("http://localhost:57789/");
listener.Start();
listener.BeginGetContext(ListenerCallback, listener);
}
示例6: ListenThread
private void ListenThread()
{
try
{
listener = new HttpListener();
foreach (string prefix in prefixes)
{
listener.Prefixes.Add(prefix);
}
listener.Start();
while (true)
{
HttpListenerContext context = listener.GetContext();
Debug.LogFormat("Recieved request from {0}.", context.Request.RemoteEndPoint.ToString());
context.Response.StatusCode = 200;
lock (waitingContexts)
{
waitingContexts.AddLast(context);
}
}
}
catch(Exception e)
{
Debug.LogErrorFormat("Web server error at {0}.", e.Source);
Debug.LogError(e.Message, this);
}
}
示例7: EndPointListener
private ArrayList _unhandled; // List<ListenerPrefix> unhandled; host = '*'
#endregion Fields
#region Constructors
public EndPointListener(HttpListener listener, IPAddress addr, int port, bool secure)
{
Listener = listener;
if (secure)
{
#if SSL
this.secure = secure;
cert = listener.LoadCertificateAndKey (addr, port);
#else
throw new Exception("SSL is not supported");
#endif
}
_endpoint = new IPEndPoint(addr, port);
_sock = new Socket(addr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
_sock.Bind(_endpoint);
_sock.Listen(500);
var args = new SocketAsyncEventArgs {UserToken = this};
args.Completed += OnAccept;
Socket dummy = null;
Accept(_sock, args, ref dummy);
_prefixes = new Hashtable();
_unregistered = new Dictionary<HttpConnection, HttpConnection>();
}
示例8: Main
static void Main()
{
Console.Title = "Samples.CustomChecks.3rdPartySystem";
Console.WriteLine("Press enter key to toggle the server to return a error or success");
Console.WriteLine("Press any key to exit");
using (listener = new HttpListener())
{
listener.Prefixes.Add("http://localhost:57789/");
listener.Start();
listener.BeginGetContext(ListenerCallback, listener);
while (true)
{
ConsoleKeyInfo key = Console.ReadKey();
Console.WriteLine();
if (key.Key != ConsoleKey.Enter)
{
return;
}
listener.Close();
if (isReturningOk)
{
Console.WriteLine("\r\nCurrently returning success");
}
else
{
Console.WriteLine("\r\nCurrently returning error");
}
isReturningOk = !isReturningOk;
}
}
}
示例9: AddPrefix
public static void AddPrefix(ILogger logger, string prefix, HttpListener listener)
{
lock (ip_to_endpoints)
{
AddPrefixInternal(logger, prefix, listener);
}
}
示例10: AddListener
public static void AddListener(HttpListener listener)
{
ArrayList added = new ArrayList();
try
{
lock (ip_to_endpoints)
{
foreach (string prefix in listener.Prefixes)
{
AddPrefixInternal(prefix, listener);
added.Add(prefix);
}
}
}
catch
{
foreach (string prefix in added)
{
RemovePrefix(prefix, listener);
}
throw;
}
}
示例11: FixtureSetup
public void FixtureSetup()
{
_listener = new HttpListener(_uri.OriginalString);
_listener.Start();
_server = new Tracker();
_server.RegisterListener(_listener);
_listener.Start();
}
示例12: Server
public Server()
{
this.httpListener = new HttpListener();
this.httpListener.Prefixes.Add("http://localhost:8080/");
this.httpListener.Prefixes.Add("http://127.0.0.1:8080/");
this.httpListener.Prefixes.Add("http://test.localhost:8080/");
}
示例13: Listener
public Listener ()
{
EndPoints = new List<IPEndPoint> ();
listener = new HttpListener ();
listener.Prefixes.Add (KeepAliveTest.URL);
listener.Start ();
listener.BeginGetContext (Handle, null);
}
示例14: Configure
public void Configure(string[] prefixes, string vdir, string pdir)
{
_virtualDir = vdir;
_physicalDir = pdir;
_listener = new HttpListener();
foreach (string prefix in prefixes)
_listener.Prefixes.Add(prefix);
}
示例15: WebAppServer
/// <summary>
/// Create an instance of <see cref="WebAppServer"/>.
/// </summary>
/// <param name="urlReservation">
/// The URL reservation to listen on. This string is similar to a URL, but the
/// hostname may be a strong wildcard ('+') or a weak wildcard ('*'). E.g. "http://+:8080/".
/// </param>
public WebAppServer(string urlReservation)
{
_urlRegex = new Regex("^" + urlReservation.Replace("*", ".*?").Replace("+", ".*?"), RegexOptions.IgnoreCase);
_listener = new HttpListener();
_listener.Prefixes.Add(urlReservation);
_disconnectHandler = new DisconnectHandler(_listener);
var uri = new Uri(urlReservation.Replace("*", "localhost").Replace("+", "localhost"));
_webAppConfiguration = new WebAppConfiguration(uri);
StaticFiles = new StaticFileSpecCollection();
}