• 0

[c#] Socket.select


Question

in the server componet of my app it has multiple clients conencting, so insted of loads of threads each client socket is put in to an arraylist and then a clone of this is put in to socket.select in the ready to read field

this works for 1 and 2 clients when it gets to 3 things get weird

3 clients join in order 1, 2, 3,

client 3 cannot say anything to the server

client 2 can say anything he wants to server

client 1 can say only 1 thing to server

i have traced it throuth and found it seems to think client 2 has data to be read when it doesent.

so

client 3 speaks:

select thinks 2 and 3 have data, it blocks on 2

client 2 speaks:

select thinks client 2 has data and it does

client 1 speaks:

select thinks 1 and 2 have data it handels 1 then blocks on 2.

it never mistakes data in client 2 unless another client has data.

i have checked everythign and can find nothing that would casue this.

so i rewrote the code to use poll insted of select and poll each socket indevidaly insted then continue as normal if data is found

this works perfectly why?? why does select not work??

this is for an assingment so i need to use select :(

anyone got any ideas on this??

code bits:

//Old Select method does not work!!!
      
selsockList = (ArrayList)sockList.Clone();

Socket.Select(selsockList, null, null, 1000);

for (int i=0; i < (selsockList.Count); i++)
{
//read
//do stuff

//new poll method

for (int i=0; i < (sockList.Count); i++)
{	

  if( ((Socket)sockList[i]).Poll(1000, SelectMode.SelectRead) )
  {
     //read
    //do stuff

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.