本文整理汇总了C#中Server.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Server.Stop方法的具体用法?C# Server.Stop怎么用?C# Server.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main (string [] args)
{
Server http = new Server ();
Proxy proxy = new Proxy ();
new Thread (http.Run).Start ();
new Thread (proxy.Run).Start ();
IPAddress ip = GetIPv4Address (Dns.GetHostName ());
HttpWebRequest request = (HttpWebRequest) WebRequest.Create ("http://" + ip.ToString () + ":8080/default.htm");
request.Proxy = new WebProxy (ip.ToString (), 8081);
try {
HttpWebResponse response = (HttpWebResponse) request.GetResponse ();
Assert.IsNull (response.CharacterSet, "#A1");
Assert.AreEqual (HttpStatusCode.OK, response.StatusCode, "#A2");
Assert.AreEqual (string.Empty, response.ContentEncoding, "#A3");
Assert.AreEqual (string.Empty, response.ContentType, "#A4");
using (StreamReader sr = new StreamReader (response.GetResponseStream ())) {
string body = sr.ReadToEnd ();
Assert.AreEqual ("<html><body>ok</body></html>", body, "#A5");
}
} catch (WebException ex) {
if (ex.Response != null) {
StreamReader sr = new StreamReader (ex.Response.GetResponseStream ());
Console.WriteLine (sr.ReadToEnd ());
}
throw;
} finally {
http.Stop ();
proxy.Stop ();
}
}
示例2: Main
public static void Main(string[] args)
{
string name = "Foobar Mirror";
ushort port = 3690;
if (args.Length > 0)
name = args[0];
if (args.Length > 1)
port = UInt16.Parse (args[1]);
server = new Server (name);
server.Port = port;
server.Start ();
ServiceLocator locator = new ServiceLocator ();
locator.Found += OnServiceFound;
locator.Removed += OnServiceRemoved;
locator.Start ();
Console.WriteLine ("Press enter to quit");
Console.ReadLine ();
foreach (Client client in clients) {
client.Logout ();
}
locator.Stop ();
server.Stop ();
}
示例3: Start
/// <summary>
/// Starts the web server.
/// </summary>
public void Start()
{
new Thread(() =>
{
// create the cross process service
var svcHost = new ServiceHost(_serviceProvider, new Uri("net.pipe://localhost/testhost"));
svcHost.AddServiceEndpoint(typeof(ITestHostService), new NetNamedPipeBinding(), "");
// service must be set to single instance mode
svcHost.Description.Behaviors.Find<ServiceBehaviorAttribute>()
.InstanceContextMode = InstanceContextMode.Single;
// open and wait for close event
svcHost.Open();
_hostCloseEvent.WaitOne();
svcHost.Close();
}).Start();
new Thread(() =>
{
// start the web server process
var server = new Server(_port, "/", _physicalPath);
// start and wait for cstop event
server.Start();
_serverStopEvent.WaitOne();
server.Stop();
}).Start();
}
示例4: OneHundredConcurrentSimpleGet
public void OneHundredConcurrentSimpleGet()
{
var server = new Server(3003);
server.Start(Application.Run);
var uri = new Uri("http://localhost:3003/");
var bag = new ConcurrentBag<string>();
const int count = 100;
for (int i = 0; i < count; i++)
{
var client = new WebClient();
client.DownloadStringCompleted += (sender, args) =>
{
bag.Add(args.Result);
client.Dispose();
};
client.DownloadStringAsync(uri);
}
SpinWait.SpinUntil(() => bag.Count == count, 10000);
server.Stop();
Assert.Equal(count, bag.Count);
foreach (var actual in bag)
{
Assert.Equal(Index.Html, actual);
}
}
示例5: ServerThreadStart
public void ServerThreadStart()
{
try
{
Server server = new Server();
server.SaveFilenameOverride = savefilename;
server.exit = exit;
DummyNetServer netServer = new DummyNetServer();
netServer.SetPlatform(new GamePlatformNative());
netServer.SetNetwork(dummyNetwork);
server.mainSockets = new NetServer[3];
server.mainSockets[0] = netServer;
for (; ; )
{
server.Process();
Thread.Sleep(1);
platform.singlePlayerServerLoaded = true;
if (exit != null && exit.GetExit()) { server.Stop(); break; }
if (platform.singlepLayerServerExit)
{
// Exit thread and reset shutdown variable
server.Exit();
platform.singlepLayerServerExit = false;
}
}
exit.SetExit(false);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
示例6: Main
public static void Main(string[] args)
{
Server Servidor = new Server("127.0.0.1", 7777);
Servidor.Start();
Servidor.Stop();
System.Console.WriteLine("ya ta!!");
}
示例7: Use
public void Use(Server server, string[] tokens)
{
server.Broadcast("The server is shutting down.");
server.Logger.Log(Logger.LogLevel.Info, "The server is shutting down.");
Thread.Sleep(5000);
server.Stop();
Thread.Sleep(10);
Console.WriteLine("Press Enter to exit.");
}
示例8: Main
static void Main(string[] args)
{
var application = new Application();
var server = new Server(application.App, 3000);
server.Start();
System.Console.WriteLine("Running on port 3000");
System.Console.Write("Press Enter to quit: ");
System.Console.ReadLine();
server.Stop();
}
示例9: Main
static void Main(string[] args)
{
// Creates the server
Server server = new Server();
// Starts the server
server.Start(8000);
while (Console.ReadLine() != "quit");
// Stops the server
server.Stop();
}
示例10: ConnectPressed
public RedirectResult ConnectPressed(Models.IndexModel Model)
{
// Create the server
Main = new Server(Port);
Main.Start();
if (!Main.Connect(Model.ID))
{
Main.Stop();
// Server failed to connect
return Redirect("ConnectFailed");
}
// Server connected succesfully
return Redirect("Controller");
}
示例11: SimpleGet
public void SimpleGet()
{
var server = new Server(3001);
server.Start(Application.Run);
string actual;
using (var client = new WebClient())
{
actual = client.DownloadString("http://localhost:3001/");
}
server.Stop();
Assert.Equal(Index.Html, actual);
}
示例12: Main
static void Main(string[] args)
{
var server = new Server(5002);
var game = new Game(server, new ConsoleLogging());
server.Start();
Console.WriteLine("Running...");
Console.ReadLine();
server.Stop();
}
示例13: ClientFullDataEmpty
public void ClientFullDataEmpty()
{
Listener listener = new Listener(endPoint);
ClientsManager clientsManager = new ClientsManager();
Server server = new Server(listener, clientsManager);
server.Start();
protocol.Connect(endPoint, ref desktopSocket);
protocol.SendObject(new Command(Command.Commands.FullData, string.Empty), desktopSocket);
Command com = protocol.ReadObject(desktopSocket, typeof(Command)) as Command;
server.Stop();
Assert.AreEqual(0, com.ValuesList.Count);
}
示例14: Main
static void Main(string[] args)
{
using (var serv = new Server())
{
Console.WriteLine("Starting server...");
serv.Start();
Console.WriteLine("Listening. Press any key to stop.");
Console.ReadKey();
Console.WriteLine("Stopping server...");
serv.Stop();
Console.WriteLine("Stopped.");
}
Console.WriteLine("Fin. Press any key to exit.");
Console.ReadKey();
}
示例15: Main
static void Main(string[] args)
{
var server = new Server("localhost", 13337);
server.Get("http://localhost:13337/", (req, res) => res.Write("Hello World!").Close());
//to have json output uncomment the next line and comment out the previous one.
//server.Get("http://localhost:13337" ,(req, res) => res.WriteAsJson(new {Hello = "world"}));
server.Start();
Console.WriteLine("Server running");
while (Console.ReadLine() == null)
Thread.Sleep(100);
server.Stop();
}