本文整理汇总了C#中System.Net.Sockets.TcpListener.AcceptIncomingConnection方法的典型用法代码示例。如果您正苦于以下问题:C# TcpListener.AcceptIncomingConnection方法的具体用法?C# TcpListener.AcceptIncomingConnection怎么用?C# TcpListener.AcceptIncomingConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpListener
的用法示例。
在下文中一共展示了TcpListener.AcceptIncomingConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public void SetUp()
{
Listener = new TcpListener(IPAddress.Any, 1235);
Listener.Start();
var fA = Listener.AcceptIncomingConnection();
var fB = Network.ConnectTo("localhost", 1235);
fA.GetCompletionEvent().Wait();
A = fA.Result as TcpClient;
fB.GetCompletionEvent().Wait();
B = fB.Result as TcpClient;
Listener.Stop();
StreamA = A.GetStream();
StreamB = B.GetStream();
}
示例2: AcceptConnectionsTask
static IEnumerator<object> AcceptConnectionsTask (TcpListener server) {
server.Start();
try {
int nextId = 0;
while (true) {
var connection = server.AcceptIncomingConnection();
yield return connection;
Peer peer = new Peer { PeerId = nextId++ };
TcpClient client = connection.Result as TcpClient;
client.Client.Blocking = false;
var peerTask = PeerTask(client, peer);
Scheduler.Start(peerTask, TaskExecutionPolicy.RunAsBackgroundTask);
}
} finally {
server.Stop();
}
}