private void Run()
{
if (isDisposed == true)
{
throw new ObjectDisposedException("ZYServer is Disposed");
}
IPEndPoint myEnd = new IPEndPoint(IPAddress.Any, Port);
if (Host.Equals("ipv6any", StringComparison.CurrentCultureIgnoreCase))
{
myEnd = new IPEndPoint(IPAddress.IPv6Any, Port);
}
else if (!Host.Equals("any",StringComparison.CurrentCultureIgnoreCase))
{
if (String.IsNullOrEmpty(Host))
{
IPHostEntry p = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress s in p.AddressList)
{
if (!s.IsIPv6LinkLocal && s.AddressFamily != AddressFamily.InterNetworkV6)
{
myEnd = new IPEndPoint(s, Port);
break;
}
}
}
else
{
try
{
myEnd = new IPEndPoint(IPAddress.Parse(Host), Port);
}
catch (FormatException)
{
IPHostEntry p = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress s in p.AddressList)
{
if (!s.IsIPv6LinkLocal)
myEnd = new IPEndPoint(s, Port);
}
}
}
}
sock = new Socket(myEnd.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
sock.Bind(myEnd);
sock.Listen(512);
ReceiveTimeout = 1000;
var memoryPool = new Thruster.FastMemoryPool<byte>();
for (int i = 0; i < MaxConnectCout; i++)
{
var netSend = new NetSend(true);
ZYSocketAsyncEventArgs socketasyn = new ZYSocketAsyncEventArgs(
new LinesReadStream(MaxBufferSize),
new BufferWriteStream(memoryPool, netSend, netSend),
netSend,
netSend,
memoryPool,
Encoding.UTF8
);
netSend.SetAccpet(socketasyn);
socketasyn.Completed += new EventHandler<ZYSocketAsyncEventArgs>(Asyn_Completed);
Accept(socketasyn);
}
}