本文整理汇总了C#中HttpServer.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.Stop方法的具体用法?C# HttpServer.Stop怎么用?C# HttpServer.Stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer
的用法示例。
在下文中一共展示了HttpServer.Stop方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
_httpsv = new HttpServer(4649);
//_httpsv.Sweeping = false;
_httpsv.AddWebSocketService<Echo>("/Echo");
_httpsv.AddWebSocketService<Chat>("/Chat");
_httpsv.OnGet += (sender, e) =>
{
onGet(e);
};
_httpsv.OnError += (sender, e) =>
{
Console.WriteLine(e.Message);
};
_httpsv.Start();
Console.WriteLine("HTTP Server listening on port: {0} service path:", _httpsv.Port);
foreach (var path in _httpsv.ServicePaths)
Console.WriteLine(" {0}", path);
Console.WriteLine();
Console.WriteLine("Press any key to stop server...");
Console.ReadLine();
_httpsv.Stop();
}
示例2: Main
public static void Main(string [] args)
{
_httpsv = new HttpServer (4649);
#if DEBUG
_httpsv.Log.Level = LogLevel.TRACE;
#endif
_httpsv.RootPath = ConfigurationManager.AppSettings ["RootPath"];
//_httpsv.KeepClean = false;
_httpsv.AddWebSocketService<Echo> ("/Echo");
_httpsv.AddWebSocketService<Chat> ("/Chat");
_httpsv.OnGet += (sender, e) =>
{
onGet (e);
};
_httpsv.OnError += (sender, e) =>
{
Console.WriteLine (e.Message);
};
_httpsv.Start ();
Console.WriteLine ("HTTP Server listening on port: {0} service path:", _httpsv.Port);
foreach (var path in _httpsv.ServicePaths)
Console.WriteLine (" {0}", path);
Console.WriteLine ();
Console.WriteLine ("Press enter key to stop the server...");
Console.ReadLine ();
_httpsv.Stop ();
}
示例3: Main
static void Main(string[] args)
{
HttpServer http = new HttpServer();
http.ProcessRequest = (request, response) =>
{
Console.WriteLine(request.Url);
if (request.Url != "/foo")
{
response.WriteLine("Hello from {0}.", request.Url);
}
else
{
response.StatusCode = HttpStatusCode.NotFound;
}
};
http.Start();
Console.WriteLine("Press enter to stop HTTP server.");
Console.ReadLine();
http.Stop();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
示例4: ForcedShutdown
public void ForcedShutdown()
{
using (var server = new HttpServer())
{
server.ShutdownTimeout = TimeSpan.FromSeconds(1);
server.RequestReceived += (s, e) =>
{
// Start closing the server.
ThreadPool.QueueUserWorkItem(p => server.Stop());
// Wait some time to fulfill the request.
Thread.Sleep(TimeSpan.FromSeconds(30));
using (var writer = new StreamWriter(e.Response.OutputStream))
{
writer.WriteLine("Hello!");
}
};
server.Start();
var request = (HttpWebRequest)WebRequest.Create(
String.Format("http://{0}/", server.EndPoint)
);
GetResponseFromRequest(request);
}
}
示例5: Main
public static void Main(string [] args)
{
_httpsv = new HttpServer (4649);
//_httpsv = new HttpServer (4649, true);
#if DEBUG
_httpsv.Log.Level = LogLevel.TRACE;
#endif
_httpsv.RootPath = ConfigurationManager.AppSettings ["RootPath"];
//var certFile = ConfigurationManager.AppSettings ["ServerCertFile"];
//var password = ConfigurationManager.AppSettings ["CertFilePassword"];
//_httpsv.Certificate = new X509Certificate2 (certFile, password);
//_httpsv.KeepClean = false;
_httpsv.AddWebSocketService<Echo> ("/Echo");
_httpsv.AddWebSocketService<Chat> ("/Chat");
_httpsv.OnGet += (sender, e) =>
{
onGet (e);
};
_httpsv.Start ();
if (_httpsv.IsListening)
{
Console.WriteLine ("HTTP Server listening on port: {0} service path:", _httpsv.Port);
foreach (var path in _httpsv.WebSocketServices.ServicePaths)
Console.WriteLine (" {0}", path);
Console.WriteLine ();
}
Console.WriteLine ("Press Enter key to stop the server...");
Console.ReadLine ();
_httpsv.Stop ();
}
示例6: Run
public void Run()
{
var provider = new CommandLineValueProvider();
var buildUri = new UriBuilder("http://localhost:8008/MagnumBenchmark");
provider.GetValue("port", x =>
{
buildUri.Port = int.Parse(x.ToString());
return true;
});
provider.GetValue("path", x =>
{
buildUri.Path = x.ToString();
return true;
});
var input = new ChannelAdapter();
ChannelConnection connection = input.Connect(x =>
{
x.AddConsumerOf<ServerEvent>()
.OnCurrentSynchronizationContext()
.UsingConsumer(m => Console.WriteLine("Server " + m.EventType));
});
var serverUri = buildUri.Uri;
Console.WriteLine("Using server uri: " + serverUri);
var server = new HttpServer(serverUri, new ThreadPoolFiber(), input, new[]
{
new VersionConnectionHandler(),
});
server.Start();
Console.WriteLine("Started: press a key to shutdown");
Console.ReadKey();
server.Stop();
Console.WriteLine("Stopping server");
Console.ReadKey();
}
示例7: Main
//.........这里部分代码省略.........
// To change the wait time for the response to the WebSocket Ping or Close.
httpsv.WaitTime = TimeSpan.FromSeconds (2);
#endif
/* To provide the secure connection.
var cert = ConfigurationManager.AppSettings["ServerCertFile"];
var passwd = ConfigurationManager.AppSettings["CertFilePassword"];
httpsv.SslConfiguration.ServerCertificate = new X509Certificate2 (cert, passwd);
*/
/* To provide the HTTP Authentication (Basic/Digest).
httpsv.AuthenticationSchemes = AuthenticationSchemes.Basic;
httpsv.Realm = "WebSocket Test";
httpsv.UserCredentialsFinder = id => {
var name = id.Name;
// Return user name, password, and roles.
return name == "nobita"
? new NetworkCredential (name, "password", "gunfighter")
: null; // If the user credentials aren't found.
};
*/
// To set the document root path.
httpsv.RootPath = ConfigurationManager.AppSettings["RootPath"];
// To set the HTTP GET method event.
httpsv.OnGet += (sender, e) => {
var req = e.Request;
var res = e.Response;
var path = req.RawUrl;
if (path == "/")
path += "index.html";
var content = httpsv.GetFile (path);
if (content == null) {
res.StatusCode = (int) HttpStatusCode.NotFound;
return;
}
if (path.EndsWith (".html")) {
res.ContentType = "text/html";
res.ContentEncoding = Encoding.UTF8;
}
res.WriteContent (content);
};
// Not to remove the inactive WebSocket sessions periodically.
//httpsv.KeepClean = false;
// To resolve to wait for socket in TIME_WAIT state.
//httpsv.ReuseAddress = true;
// Add the WebSocket services.
httpsv.AddWebSocketService<Echo> ("/Echo");
httpsv.AddWebSocketService<Chat> ("/Chat");
/* Add the WebSocket service with initializing.
httpsv.AddWebSocketService<Chat> (
"/Chat",
() => new Chat ("Anon#") {
Protocol = "chat",
// To ignore the Sec-WebSocket-Extensions header.
IgnoreExtensions = true,
// To validate the Origin header.
OriginValidator = val => {
// Check the value of the Origin header, and return true if valid.
Uri origin;
return !val.IsNullOrEmpty () &&
Uri.TryCreate (val, UriKind.Absolute, out origin) &&
origin.Host == "localhost";
},
// To validate the Cookies.
CookiesValidator = (req, res) => {
// Check the Cookies in 'req', and set the Cookies to send to the client with 'res'
// if necessary.
foreach (Cookie cookie in req) {
cookie.Expired = true;
res.Add (cookie);
}
return true; // If valid.
}
});
*/
httpsv.Start ();
if (httpsv.IsListening) {
Console.WriteLine ("Listening on port {0}, and providing WebSocket services:", httpsv.Port);
foreach (var path in httpsv.WebSocketServices.Paths)
Console.WriteLine ("- {0}", path);
}
Console.WriteLine ("\nPress Enter key to stop the server...");
Console.ReadLine ();
httpsv.Stop ();
}
示例8: SocketServer
public SocketServer()
{
var wssv = new HttpServer(8140);
GameEngine gameEngine = new GameEngine();
ChatEngine chatEngine = new ChatEngine();
wssv.AddWebSocketService<GameService>("/game", () => new GameService(gameEngine));
wssv.AddWebSocketService<ChatService>("/chat", () => new ChatService(chatEngine));
wssv.Start();
Console.ReadKey(true);
wssv.Stop();
}
示例9: Start_and_stop_service
public void Start_and_stop_service()
{
const int port = 8080;
using (var server = new HttpServer())
{
Assert.AreEqual(HttpServerStatus.Stopped, server.Status);
Assert.IsNull(server.EndPoint);
server.Start(port, null);
Assert.AreEqual(HttpServerStatus.Started, server.Status);
Assert.AreEqual(port, server.EndPoint.Port);
server.Stop();
Assert.AreEqual(HttpServerStatus.Stopped, server.Status);
Assert.IsNull(server.EndPoint);
}
}
示例10: Main
public static void Main (string [] args)
{
_httpsv = new HttpServer (4649);
//_httpsv = new HttpServer (4649, true); // For Secure Connection
#if DEBUG
// Changing the logging level
_httpsv.Log.Level = LogLevel.Trace;
#endif
/* For Secure Connection
var cert = ConfigurationManager.AppSettings ["ServerCertFile"];
var password = ConfigurationManager.AppSettings ["CertFilePassword"];
_httpsv.Certificate = new X509Certificate2 (cert, password);
*/
/* For HTTP Authentication (Basic/Digest)
_httpsv.AuthenticationSchemes = AuthenticationSchemes.Basic;
_httpsv.Realm = "WebSocket Test";
_httpsv.UserCredentialsFinder = identity => {
var expected = "nobita";
return identity.Name == expected
? new NetworkCredential (expected, "password", "gunfighter")
: null;
};
*/
// Not to remove inactive clients in WebSocket services periodically
//_httpsv.KeepClean = false;
// Setting the document root path
_httpsv.RootPath = ConfigurationManager.AppSettings ["RootPath"];
// Setting HTTP method events
_httpsv.OnGet += (sender, e) => onGet (e);
// Adding WebSocket services
_httpsv.AddWebSocketService<Echo> ("/Echo");
_httpsv.AddWebSocketService<Chat> ("/Chat");
/* With initializing
_httpsv.AddWebSocketService<Chat> (
"/Chat",
() => new Chat ("Anon#") {
Protocol = "chat",
// Checking Origin header
OriginValidator = value => {
Uri origin;
return !value.IsNullOrEmpty () &&
Uri.TryCreate (value, UriKind.Absolute, out origin) &&
origin.Host == "localhost";
},
// Checking Cookies
CookiesValidator = (req, res) => {
foreach (Cookie cookie in req) {
cookie.Expired = true;
res.Add (cookie);
}
return true;
}
});
*/
_httpsv.Start ();
if (_httpsv.IsListening) {
Console.WriteLine (
"An HTTP server listening on port: {0}, providing WebSocket services:", _httpsv.Port);
foreach (var path in _httpsv.WebSocketServices.Paths)
Console.WriteLine ("- {0}", path);
}
Console.WriteLine ("\nPress Enter key to stop the server...");
Console.ReadLine ();
_httpsv.Stop ();
}