473,785 Members | 3,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket::Select problem

Hi guys,
I have just a problem with the Select timeout parameter.
The MSDN tells us:
microSeconds
The time-out value, in microseconds. A -1 value indicates an infinite
time-out.

I try to use -1 as timeout value but the select returns immediately.
That's correct if, at least, one of the list passed to the select has count
property 0.
But that's not happening to me.

Is it a bug? Did I make any kind of errors?
Someone seems to have the same problem using C#:
http://groups.google.it/group/micros...a02804279079e3

Thanks in advance.
Sektor.

Following the code used (it's like a proxy):
// Waiting for a connection
Socket^ fromClient = _accept(); // TcpListener, Start, AcceptSocket
// Create a connection to the server
TcpClient^ toServer = gcnew TcpClient();
toServer->Connect(Server Name, ServerPort);

//These work well
//bool b1 = fromClient->Poll(-1, SelectMode::Sel ectRead);
//bool b2 = toServer->Client->Poll(-1, SelectMode::Sel ectRead);

ArrayList^ checkRead = gcnew ArrayList();
array<Byte>^ buf = gcnew array<Byte>(DEF AULT_BUF_SIZE);

int n = 0;
bool toBeClose = false;
// Forward data
while (1) {
checkRead->Add(fromClient );
checkRead->Add(toServer->Client);
try {
Socket::Select( checkRead, nullptr, nullptr, -1);
for each (Socket^ s in checkRead) {
n = s->Receive(buf) ;
if (n <= 0) {
toBeClose = true;
break;
}
Array::Resize(b uf, n);
Byte prx;
if (s->Equals(fromCli ent)) {
toServer->GetStream()->Write(buf, 0, n);
} else {
fromClient->Send(buf);
}
Array::Resize(b uf, DEFAULT_BUF_SIZ E);
}
} catch (SocketExceptio n^ e) {
Console::WriteL ine("Sockets closed");
Console::WriteL ine(e->ToString());
return;
}
checkRead->Clear();
if (toBeClose)
break;
}

Sep 5 '06 #1
0 991

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2462
by: Dario | last post by:
I have an unmanaged library that handle many TCP/IP connections. In my .NET application i want to test if there is input available on these connections. Using an existing function of the unmanaged library I'm able to retrieve the list of Int32 socket-descriptors handled by the unmanaged library. How can I use this list of Int32 socket-descriptors inside my C# program to test if there is input available on these socket-descriptors? I...
1
1441
by: dexter15820 | last post by:
I am having a socket problem after upgrading my .net framework 1.1 to the latest patch level. After the upgrade I can establish a connection but I cannot read from the socket. If I remove the patch I can read from the socket. Do you know of any security settings for .net that i need to change?
1
1589
by: osaleh | last post by:
I am trying to execute a Socket.Select() statement on an arraylist of sockets. The problem is that I can only go up to 64 sockets at a time. I know that I have to manupilate the FD_SetSize to increase the limit. How do you do that in C# in the .NET Visual Studio environmrnt.
0
1724
by: Markus S. | last post by:
Hello! I have two questions about Socket.Select(): 1) How is it possible to interrupt Socket.Select()? I'm calling Socket.Select() in a worker thread. When new sockets are added (from another thread) I want to interrupt the Select() so it can get restarted with the new sockets being added. This has to happen quickly so I can't wait for the timeout. Thread.Interrupt() seems to do nothing.
2
1834
by: yaron | last post by:
i get an SocketException exception when using socket select method. how do i know what is the socket that cause the exception ? can i get this info from the exception instance ? Thanks.
9
8712
by: Stuart | last post by:
I am trying to execute a Socket.Select() statement on an arraylist of sockets. The problem is that I can only go up to 64 sockets at a time. I know that I have to manipulate the FD_SetSize to increase the limit. How do you do that in C# in the .NET Visual Studio environment? I could potentially have 1000's of simultaneous connections, so running each socket in it's own thread doesn't seem very practical. Stuart.
1
17551
by: Mr. Beck | last post by:
Hello, Please Help..... I have been working with some tcp/ip socket communication within a C# program recently. Basicly, I have a program (myProblemProgram) that has a socket connected to another program for information passing. Upon receiving a particular "command" from the the information passing program, myProblemProgram will launch a separate thread to do individual communication with another file transfer program. The thread...
6
6594
by: Dilip | last post by:
I don't know how I missed this piece for so long (this may also be old news to you guys) but in this ACMQueue article, Michi Henning goes to elaborate lengths to detail how even today designing a good API requires a lot experience and effort by illustrating the example of something as common place as the select() function call available in sockets. The example focuses on the design decision surrounding the Select() call in C#. It comes...
16
3859
by: =?iso-8859-1?q?|-|e|=5F|=5F_B0=DD?= | last post by:
hi all! I got a problem. I declared a SOCKET var in my C program but when i compiled the program it displayed like *--------------------------------------------------------------* *'SOCKET': illegal use of this type as an expression * * C:\..\..\..\include\winsock2.h: see declaration of 'SOCKET' * *--------------------------------------------------------------* What i wrote in my program is like this..:
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.