views:

951

answers:

3

I have a simple udp listener written in c++ using win32 when I compile and run the program under debug mode it works perfectly, and I'm clearly able to see the information from the packets that I'm receiving. When I run this same code as a release build it compiles fine and seems to run fine, but its not printing out any packet information like it did under the release build. I've tried to mirror the build configurations to match exactly but its still happening. Any suggestions would be greatly appreciated.

+1  A: 

The code that outputs debugging information about the packets is probably stripped out for performance reasons in the release build.

This is done mostly by two things:

  • conditional preprocessor directives that check against debug mode and generate appropriate code in that mode.
  • linking against debug version of libraries.

Dropping those stuff is in fact, the primary purpose you are building a release version. You ain't gonna need debugging info so you won't be sacrificing performance for it. If you're really want to do so, then why don't you just ship the debug build [update: as noted in a comment, seems the license doesn't allow you to distribute software linked against debug libs]? It's the most similar configuration (you can't get more a config similar than identical, can you?)

Mehrdad Afshari
You can't ship a build linked to the debug runtime DLLs under the license.
RBerteig
@RBerteig: Thanks for the note, I didn't know it.
Mehrdad Afshari
A: 

How exactly are you printing the information? Some macros like TRACE don't do anything in release builds.

Or if you're printing using fprintf or some equivalent, it doesn't necessarily write anything until you call fflush - the debug version may do that for you more frequently.

Peter
+1  A: 

This is more likely an issue of not initializing variables to some initial value, so in debug they have some sort of value, but in release, most things are initialized zero (NULL). So, some condition/branch may be taking place, that you do not expect... Without your source code for example, it's REALLY hard to spot issues.

This has bit me more than once.. :)

This is assuming you are not expecting to see anything using stuff like OutputDebugString() as Mehrdad suggested...

Also, make sure your packets are UNDER 1024 bytes in size, or you will NOT get them. Took me a while to figure this one out back when XP came out, and I couldn't figure out why my code worked on 2000, but not XP... Even though send (sendto) would return success, it never actually SENT the packet..

Anyways, I've dealt with UDP a lot on Win32, so if you give me some example code I should be able to help more...

But anyways, check that ALL your variables are initialized to some sort of default value on both the sender and the receiver, (which is just good practice), and then re-build it and try again. Also, check your packet size with a sizeof() before it sends, and if it's greater than 1024 bytes, don't bother... It's also a good idea to check size of the received packet, and if it's not exactly the size you expect, then drop the packet. This holds MORE true for broadcasts, but still applies.

Let me know if any of this helped, I posted a LOT of UDP code on another question here a little while back, and that code works, you might want to refer to it.

LarryF
Can it receive more the 1024 bytes? Because the machine sending the packets is running Linux and that can send packets greater then 1024 bytes.
whatWhat
In XP I was not able to do a recvfrom() and get more than 1024 bytes. There is some sort of limit. I'll have to search for the info I found originally. Have you tried this same app on Win2000? It may just work, but I haven't seen your code yet, so I can't say for certain.
LarryF