Lenard Gunda wrote:
Hi,
I checked the .NET 1.1 version of Select with Reflector, and I think it
should work there too with many sockets.
What kind of IList do you use for your sets? Is it an array or ArrayList
or something of your own?
-Lenard
Here is a simplified version of the code:
ArrayList sockList = new ArrayList();
ArrayList copyList = new ArrayList();
Socket SocketRX = new Socket(AddressF amily.InterNetw ork,
SocketType.Stre am, ProtocolType.Tc p);
IPEndPoint iep = new IPEndPoint(IPAd dress.Any, clsMain.PortTCP );
byte[] data;
int recv;
SocketRX.SetSoc ketOption(Socke tOptionLevel.So cket,SocketOpti onName.ReuseAdd ress,
1);
SocketRX.Bind(i ep);
SocketRX.Listen (1000);
while (!quit)
{
if (SocketRX.Poll( 0,SelectMode.Se lectRead)) //Test for new connections
{ //New Connection
Socket NewSocket = SocketRX.Accept (); //Accept the connection
SockInfo.IPEndP =(IPEndPoint)Ne wSocket.RemoteE ndPoint;
sockList.Add(Ne wSocket); //Add Socket to the SocketList
Console.WriteLi ne("Soc: Connected to {0}", SockInfo.IPEndP .ToString());
}
else
{ //Check for any pending data
copyList = new ArrayList(sockL ist);
Socket.Select(c opyList, null, null, 5000000); //block for .5 second
foreach(Socket client in copyList) //Read data from sockets that have
data
{
data = new byte[RXBufferSize];
try
{
recv = client.Receive( data); //Read the incomming data
}
catch (Exception ex)
{
recv=0;
}
if (recv == 0)
{
CloseSocket(cli ent);
}
else
{
//Proccess my data here....
}
}
}
}