473,698 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with select() and sockets...

I am having a bit of a problem, and it might have to do with my
understanding of how select works...

basically what i am trying to simulate is a system:
client->gateway->server model. The client breaks a file up into
sections and sends them to the server, through teh gateway which just
forwards info. Now upon getting the info, the server sends back an
ACK through the gateway, when the client sees the ack it sends the
next part (simeple stop_and_wait protocol) now my server is set to
randomly drop packets. and here is the problem i am having.

when no packets get dropped, everything works fine. if the first ACK
gets dropped from teh server then the client goes into a weird loop,
even if the server resends that ACK, the client never sees info coming
to it.

here is the code:

int sock;
fd_set fds;
struct time_val tv;

tv.tv_sec=3; //set timeout to 3sec
FD_ZERO(&fds);
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) //open new
socket
WriteLogDie("so cket() failed to open a new socket",client_ log);

FD_SET(sock, &fds);

if (bind(sock, (struct sockaddr *) &ClientAddr,
sizeof(ClientAd dr)) < 0) /*bind to local addr*/

if (packet==0)
SendFileName();
if (packet>0)
SendData();

select (sock+1, &fds,NULL,NULL, &tv);

if(select(sock+ 1,&fds,NULL, NULL, &tv)
RecievePacket() ;
else {
//TIMEOUT
cout << "got a timeout\n";
do {
ResendPacket();
cout << "Resending\ n";
}while (select(sock+1, &fds,NULL,NULL, &tv));
}

This code is nested in a hwile loop that just checks to see when were
done sending. This works perfectly if no packets are dropped. but if
the first ACK from the server is dropped, it goes into a loop, and
even if the gateway forwards information with the ACK later to the
client, it never shows that select() chooses to get info from the
socket. i dont know why. does anyone?

Thanks,
Adam
Jul 22 '05 #1
1 2067
Adam Balgach wrote:
I am having a bit of a problem, and it might have to do with my
understanding of how select works...

Whoops. It looks like you misspelled
news:comp.unix. programmer

(right down the hall).

[IOW, C++ knows of neither sockets nor select -- they are POSIXisms.]

HTH,
--ag

--
Artie Gold -- Austin, Texas

"If you don't think it matters, you're not paying attention."
Jul 22 '05 #2

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

Similar topics

2
3889
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add support for sockets to the system. Thread needs to unblock when: - there is socket ready to be read, or
0
1445
by: Gonçalo Rodrigues | last post by:
Hi, I have a problem with threads and sockets. I'll try to describe the problem in words with pseudo-code. I've been working on a few classes to make it easier to work with threads. This framework, let us call it that, consists in two parts. The first part is just a basic thread class deriving from threading.Thread with a few extra functionality that makes it easier for a thread to spawn a new thread and "father it". Each of its
4
2428
by: flupke | last post by:
Hi, I have a gui (made in wxPython) that enables a user to connect to a server and issue some commands. The problem occurs when i try to disconnect the client. It exits but it doesn't return to the prompt. I have to push Ctrl-C in order to have it exit completely. The GUI is closed though. This is a piece of code from the main class that connects to the server and starts a thread that handles the connection: =======================...
1
3786
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for pending connections every 500ms. I also have a vb6 application that uses the WinSock control at the other end of the communication tunel. I have to work with vb6 here because it uses less memory than .NET.
0
1261
by: raza | last post by:
Hi, I have been programmin in C# for quite some time now and recently got into sockets programming in C# though i have done it in C++ on windows/linux . I have an interesting problem at hand . I am porting a C++ tunnel library into C# . It has 2 functions WriteOut: I make a header and send it then send the actual data to the server and it calls Write function
0
1720
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.
0
1304
by: Ben | last post by:
I modified the logmonitor sdk example so it would work over a network. It works great when the client and server are running on the same PC and have administrator privileges. So I have two problems: 1) I cannot run the client without administrator privileges. If I try I get the following message: Unhandled Exception: System.Security.SecurityException: Requested registry access is not allowed. at...
2
1439
by: Vlad Dogaru | last post by:
Hello, I am trying to write a simple program to teach myself sockets. The following bit of code fails with: "connect: Socket operation on non-socket". What am I missing? #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h>
7
3005
by: psybert | last post by:
Hello everyone, Long time lurker, first time poster. I'm a beginner coder, and I've taught myself everything with the help and expertise of users and websites like this one. I normally figure out any problem, but this one really has me stumped. Basically, I have created a site that initially loads a set of "items" and their values into 17 drop down menus from an XML file. Each of those "items" when selected from the drop down menu loads...
0
8598
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9152
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
9016
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...
1
8887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8856
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...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5858
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();...
2
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
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.