本文整理汇总了C#中Server.Listen方法的典型用法代码示例。如果您正苦于以下问题:C# Server.Listen方法的具体用法?C# Server.Listen怎么用?C# Server.Listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.Listen方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ServerWillOpenSocketWhenToldToListen
public void ServerWillOpenSocketWhenToldToListen()
{
var server = new Server((req, resp) => { });
server.Listen(56565, null, null);
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
socket.Connect("localhost", 56565);
socket.Close();
}
示例2: ServerWillCloseSocket
public void ServerWillCloseSocket()
{
var server = new Server();
server.Listen(56566, null, null);
server.Close();
Assert.Throws<SocketException>(() =>
{
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
socket.Connect("localhost", 56566);
socket.Close();
});
}
示例3: ServerWillEmitCloseRequest
public void ServerWillEmitCloseRequest()
{
var server = new Server();
var closed = false;
server.OnClose(errno => closed = true);
server.Listen(56566, null, null);
var closedBefore = closed;
server.Close();
var closedAfter = closed;
Assert.Equal(false, closedBefore);
Assert.Equal(true, closedAfter);
}
示例4: ServerWillEmitRequestEvent
public void ServerWillEmitRequestEvent()
{
var requested = false;
using (var server = new Server((req, resp) =>
{
requested = true;
resp.Headers["Content-Type"] = "text/plain";
resp.Headers["Connection"] = "close";
resp.WriteHead(200, "OK");
resp.End();
}))
{
server.Listen(56567, null, null);
var webRequest = System.Net.WebRequest.Create("http://localhost:56567");
var webResponse = webRequest.GetResponse();
Assert.Equal(true, requested);
}
}
示例5: Main
static void Main(string[] args)
{
Console.WriteLine("DualSnake Server v1.0\r\nCopyright (C) Solymosi Máté 2011\r\n");
if (args.Length > 0)
{
try { LoadLevel(args[0]); }
catch { return; }
}
else
{
try { LoadLevel("Default.level"); }
catch
{
Console.WriteLine("Using built-in default map.");
Map = Tools.CreateDefaultMap(SnakeGame.FieldWidth, SnakeGame.FieldHeight);
}
}
Server<SnakePlayer> Server = new Server<SnakePlayer>(1991);
Server.Connected += new Server<SnakePlayer>.ConnectedDelegate(Server_Connected);
Server.Listen();
Console.WriteLine("\r\nListening on port 1991. Press CTRL+C to exit.");
while (true) { System.Threading.Thread.Sleep(10000); }
}
示例6: Main
static void Main()
{
Server server = new Server();
server.Listen();
}
示例7: TextCanBeSentThroughResponse
public void TextCanBeSentThroughResponse()
{
var requested = false;
using (var server = new Server((req, resp) =>
{
requested = true;
resp.Headers["Content-Type"] = "text/plain";
resp.Headers["Connection"] = "close";
resp.WriteHead(200, "OK");
resp.Write("This is a triumph");
resp.End();
}))
{
server.Listen(56567, null, null);
var webRequest = System.Net.WebRequest.Create("http://localhost:56567");
var webResponse = webRequest.GetResponse();
using (var stream = webResponse.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
var text = reader.ReadToEnd();
Assert.Equal("This is a triumph", text);
}
}
Assert.Equal(true, requested);
}
}