Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.fds-net.ru/showflat.php?Number=1283596&src=arc&showlite=
Дата изменения: Unknown
Дата индексирования: Wed Apr 13 03:23:43 2016
Кодировка: Windows-1251
Ошибка проги или .NET? - Public forum of MSU united student networks
Root | Google | Yandex | Mail.ru | Kommersant | Afisha | LAN Support
  
Technical >> Development (Archive)

Страницы: 1
aks

Рег.: 04.05.2003
Сообщений: 901
Рейтинг: -40
  Ошибка проги или .NET?
      19.06.2004 01:10
 

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

Вот код:

code:

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;
}
}





Редактировал dimka (19.06.2004 04:55)
aset
boar

Рег.: 05.09.2003
Сообщений: 36470
Рейтинг: 6913
  Re: Ошибка проги или .NET? [re: aks]
      19.06.2004 17:20
 

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



may have come in contact with nuts
Druxa
Дрюха

Рег.: 27.06.2003
Сообщений: 2722
Из: Троицк
Рейтинг: 1974
  Re: Ошибка проги или .NET? [re: aks]
      20.06.2004 01:19
 

А сюда
code:
catch(SocketException ex)
{}


часто попадаем? А то может какой finally стоит привернуть?

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



нет, я не богат... я сказочно не богат... но я и не умен...
CAXAPOK
member

Рег.: 23.04.2004
Сообщений: 184
Рейтинг: 7
  Re: Ошибка проги или .NET? [re: aks]
      20.06.2004 01:30
 

,kz
очищай acceptList

stalker
девелопер

Рег.: 01.11.2002
Сообщений: 3272
Из: Москва
Рейтинг: 4130
  Re: Ошибка проги или .NET? [re: aks]
      20.06.2004 13:18
 

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



Кстати, благородные доны, чей это вертолет позади избы?
aks

Рег.: 04.05.2003
Сообщений: 901
Рейтинг: -40
  Re: Ошибка проги или .NET? [re: aks]
      20.06.2004 18:13
 

Большое спасибо всем за внимание.

Там на самом деле константа 64 стоит, говорят во Framework 2.0 изменят.

Буду через асинхронные делать.

aset
boar

Рег.: 05.09.2003
Сообщений: 36470
Рейтинг: 6913
  Re: Ошибка проги или .NET? [re: aks]
      20.06.2004 18:45
 

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





Редактировал aset (20.06.2004 18:45)
may have come in contact with nuts
Druxa
Дрюха

Рег.: 27.06.2003
Сообщений: 2722
Из: Троицк
Рейтинг: 1974
  Re: Ошибка проги или .NET? [re: aset]
      20.06.2004 20:06
 

Quote:

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



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



нет, я не богат... я сказочно не богат... но я и не умен...
aset
boar

Рег.: 05.09.2003
Сообщений: 36470
Рейтинг: 6913
  Re: Ошибка проги или .NET? [re: Druxa]
      20.06.2004 23:01
 

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



may have come in contact with nuts
Druxa
Дрюха

Рег.: 27.06.2003
Сообщений: 2722
Из: Троицк
Рейтинг: 1974
  Re: Ошибка проги или .NET? [re: aset]
      21.06.2004 00:47
 

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

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. 2aks: А где ты про 64 нашел?



нет, я не богат... я сказочно не богат... но я и не умен...
shaller
San Jose

Рег.: 25.10.2002
Сообщений: 21640
Из: Станция 074803
Рейтинг: 15646
  Re: Ошибка проги или .NET? [re: Druxa]
      21.06.2004 11:17
 

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



'Земля наша велика и обильна, а порядка в ней нет. Приходите княжить и владеть нами'
aset
boar

Рег.: 05.09.2003
Сообщений: 36470
Рейтинг: 6913
  Re: Ошибка проги или .NET? [re: Druxa]
      21.06.2004 11:36
 

В ответ на:

.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.





Это два.



may have come in contact with nuts
Anonymous
Незарегистрирован
(10.7.20.31)

  Re: Ошибка проги или .NET? [re: aset]
      21.06.2004 14:33
 

Это три. (by .NET Reflector)

System.Socket.Select
Quote:


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.MicrosecondsToTimeValue(((long) 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
Quote:


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
Quote:


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






Так что, дейтвительно, константа стоит

Страницы: 1

Technical >> Development (Archive)

Дополнительная информация
0 зарегистрированных и 0 анонимных пользователей просматривают этот форум.

Модераторы:  DarkGray 

Печать темы

Права
      Вы можете создавать новые темы
      Вы можете отвечать на сообщения
      HTML отключен
      UBBCode включен

Рейтинг:
Просмотров темы:

Переход в