本文整理汇总了C#中System.Net.Sockets.TcpListener.GetPort方法的典型用法代码示例。如果您正苦于以下问题:C# TcpListener.GetPort方法的具体用法?C# TcpListener.GetPort怎么用?C# TcpListener.GetPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpListener
的用法示例。
在下文中一共展示了TcpListener.GetPort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunServer
private static void RunServer(ProgramOptions options)
{
var listener = new TcpListener(options.Host, options.Port);
listener.Start();
var display = new Display(options, listener.GetPort()) {Delay = .5.Seconds()};
display.Refresh();
try
{
var files = options.Directory.EnumerateFiles("*", SearchOption.AllDirectories);
var buffer = new byte[Extensions.DefaultStreamCopyBufferSize];
using (var it = files.GetEnumerator())
{
using (var client = listener.AcceptTcpClient())
using (var netStream = client.GetStream())
using (var compStream = options.Compression.HasValue
? new DeflateStream(netStream, options.Compression.Value)
: null)
using(var clearWriter = new BinaryWriter((Stream)compStream ?? netStream))
using (var aes = CreateAes(options))
using (var enc = aes?.CreateEncryptor())
using (var cryptoStream = aes != null
? new CryptoStream((Stream)compStream ?? netStream, enc, CryptoStreamMode.Write)
: null)
using (var writer = new BinaryWriter(cryptoStream ?? (Stream)compStream ?? netStream))
{
if (aes != null)
clearWriter.Write(aes.IV);
display.Stopwatch.Start();
while (it.MoveNext())
{
var file = it.Current;
display.CurrentFile = new FileProgress(
file.GetRelativePathFrom(options.Directory),
file.Length).Do(x => x.Stopwatch.Start());
var path = file.GetRelativePathFrom(options.Directory);
writer.Write(path);
writer.Write(file.Length);
using (var fileStream = file.OpenRead())
fileStream.CopyTo(writer.BaseStream, file.Length, buffer,
b =>
{
display.ByteCount += (display.CurrentFile.BytesTransferred = b);
display.Refresh();
});
display.FileCount++;
display.Refresh();
}
}
}
}
finally
{
listener.Stop();
}
}