Ошибка проги или .NET?

yaskov2006

В общем, работа с Socket.Select
На 64-65 коннекте он кидается следующий эксепшн: Index was outside the bounds of the array.
Не могу понять, видимо проблема в .NET?
Вот код:


IPHostEntry ipHostEntry = Dns.Resolve("localhost");
IPAddress ipAddress = ipHostEntry.AddressList[0];

ArrayList listenList = new ArrayList;
ArrayList acceptList = new ArrayList;
Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
sock.Bind(new IPEndPoint(ipAddress, 11000;
sock.Listen(10);

string msg = "hello";
byte [] bytes = Encoding.ASCII.GetBytes(msg);
while (true)
{
try
{
listenList.Add(sock);
Socket.Select(listenList, null, null, 1000);
try
{
foreach (Socket s in listenList )
{
Socket conn = s.Accept;
acceptList.Add(conn);
conn.Send(bytes);
Console.WriteLine("Connected clients: {0}", acceptList.Count);
}
listenList.Clear;
foreach(Socket s in acceptList )
{
listenList.Add(s);
}
}
catch(SocketException ex)
{

}
}
catch (Exception ex)
{
Console.WriteLine("Exception occured: {0}\nPress any key to continue", ex.Message);
Console.ReadLine;
break;
}
}

evgen5555

А что ты этой прогой делаешь?

rosali

А сюда

catch(SocketException ex)
{}


часто попадаем? А то может какой finally стоит привернуть?
PS 64 -- вообще разумное значение для начального размера ArrayList-а, так что может и впрямь в .NET ошибка. Это запросто, я в System.Reflection в свое время пол десятка нашел...

Ir4a

kz
очищай acceptList

VitMix

А в которой строчке собственно exception вылетает?

yaskov2006

Большое спасибо всем за внимание.
Там на самом деле константа 64 стоит, говорят во Framework 2.0 изменят.
Буду через асинхронные делать.

evgen5555

У тебя ошибка в проге, ёбта!
А дотнет тут вообще ни при чем.

rosali

У тебя ошибка в проге, ёбта!

Какая ошибка то?

evgen5555

Маза в селект нельзя такие гопы сокетов запихивать по определению.

rosali

Какому еще определению? Я не против, чтобы нельзя, но об этом надо же заранее уведомлять

Remarks
Select is a static method that determines the status of one or more Socket instances. You must place one or more sockets into an IList before you can use the Select method. Check for readability by calling Select with the IList as the checkread parameter. To check your sockets for writeability, use the checkwrite parameter. For detecting error conditions, use Checkerror. After calling Select, the IList will be filled with only those sockets that satisfy the conditions.
If you are in a listening state, readability means that a call to Accept will succeed without blocking. If you have already accepted the connection, readability means that data is available for reading. In these cases, all receive operations will succeed without blocking. Readability can also indicate whether the remote Socket has shut down the connection; in that case a call to Receive will return immediately, with zero bytes returned.
If you make a nonblocking call to Connect, writability means that you have connected successfully. If you already have a connection established, writeability means that all send operations will succeed without blocking.
If you have made a non-blocking call to Connect, the checkerror parameter identifies sockets that have not connected successfully.
Note
Use the Poll method if you only want to determine the status of a single Socket.
Note
If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Socket Version 2 API error code documentation in MSDN for a detailed description of the error.
Кароче, нету нигде про твои "горы сокетов"...
PS. 2: А где ты про 64 нашел?

otets-mihail

мб, асет имеет ввиду, что Socket.Select использует select c FD_SETSIZE=64 ?

evgen5555

.NET Framework Class Library
Socket Class [C#]
Implements the Berkeley sockets interface.
Это раз.
Four macros are defined in the header file Winsock2.h for manipulating and checking the descriptor sets. The variable FD_SETSIZE determines the maximum number of descriptors in a set. (The default value of FD_SETSIZE is 64, which can be modified by defining FD_SETSIZE to another value before including Winsock2.h.) Internally, socket handles in an fd_set structure are not represented as bit flags as in Berkeley Unix. Their data representation is opaque. Use of these macros will maintain software portability between different socket environments. The macros to manipulate and check fd_set contents are:
FD_CLR(s, *set)
Removes the descriptor s from set.
FD_ISSET(s, *set)
Nonzero if s is a member of the set. Otherwise, zero.
FD_SET(s, *set)
Adds descriptor s to set.
FD_ZERO(*set)
Initializes the set to the null set.
Это два.

Torneo

Это три. (by .NET Reflector)
System.Socket.Select

public static void Select(IList checkRead, IList checkWrite, IList checkError, int microSeconds)
{
TimeValue value1;
if checkRead == null) || (checkRead.Count == 0 && checkWrite == null) || (checkWrite.Count == 0 && checkError == null) || (checkError.Count == 0
{
throw new ArgumentNullException(SR.GetString("net_sockets_empty_select";

}
FileDescriptorSet set1 = Socket.SocketListToFileDescriptorSet(checkRead);
FileDescriptorSet set2 = Socket.SocketListToFileDescriptorSet(checkWrite);
FileDescriptorSet set3 = Socket.SocketListToFileDescriptorSet(checkError);
value1 = 0;
Socket.MicrosecondsToTimeValuelong) microSeconds ref value1);
int num1 = OSSOCK.select(0, ref set1, ref set2, ref set3, ref value1);
if (num1 == -1)
{
throw new SocketException;

}
int num2 = 0;
num2 += Socket.SelectFileDescriptor(checkRead, set1);
num2 += Socket.SelectFileDescriptor(checkWrite, set2);
num2 += Socket.SelectFileDescriptor(checkError, set3);

}

System.Net.Socket.SocketListToFileDescriptorSet

private static FileDescriptorSet SocketListToFileDescriptorSet(IList socketList)
{
FileDescriptorSet set1;
int num1;
object[] objArray1;
if socketList == null) || (socketList.Count == 0
{
return FileDescriptorSet.Empty;

}
if (socketList.Count > FileDescriptorSet.Size)
{
throw new ArgumentOutOfRangeException("socketList.Count");

}
set1 = new FileDescriptorSet(socketList.Count);
for (num1 = 0; (num1 < set1.Count); num1 += 1)
{
if socketList[num1] as Socket) == null)
{
objArray1 = new object[2];
objArray1[0] = socketList[num1].GetType.FullName;
objArray1[1] = typeof(Socket).FullName;
throw new ArgumentException(SR.GetString("net_sockets_select", objArray1;

}
set1.Array[num1] = Socket) socketList[num1]).m_Handle;

}
return set1;
}

System.Net.Sockets.FileDesctriptorSet.ctor

public FileDescriptorSet(int count)
{
this.Count = count;
this.Array = count == 0) ? null : new IntPtr[64]);
}

Так что, дейтвительно, константа стоит
Оставить комментарий
Имя или ник:
Комментарий: