Jump to content
  • Advertisement
Sign in to follow this  
rnw159

Winsock2 console program failure

This topic is 2700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My problem is that the console window jumps to system("pause") and skips any other commands or couts. If 2 system("pause") are present then the window closes after a key is pressed for the first system pause and then reopens for the seconds pause. The program continues to have a presence in the background, however, it is not visible unless there is a system("pause"). cin.get() and cin >> do not have the same effect that system("pause") has, and the window continues to remain invisible when they are called. I have narrowed it down to only happening if the program is compiled with #include <WinSock2.h>. The unique part is that even if I recompile without that header, the problem still stays for the entire project. I can only replicate the problem by creating new console projects. Once the project has been compiled with winsock2, the problem remains no matter what is written in the program.

I'm still experimenting so any new information will be posted.

Share this post


Link to post
Share on other sites
Advertisement

It's a riveting story, so keep us posted. I'm curious how it turns out.


Um thanks. Do you have any suggestions on how to fix the problem?

Share this post


Link to post
Share on other sites


Um thanks. Do you have any suggestions on how to fix the problem?


What problem?

There is no source code, no problem statement, no question...

Including wrong headers can cause problems. Not using API properly can cause problems. Bugs can cause problems. But there is nothing to go on here.

Share this post


Link to post
Share on other sites

[quote name='rnw159' timestamp='1304345881' post='4805447']
Um thanks. Do you have any suggestions on how to fix the problem?


What problem?

There is no source code, no problem statement, no question...

Including wrong headers can cause problems. Not using API properly can cause problems. Bugs can cause problems. But there is nothing to go on here.
[/quote]

Sorry, the reason there is no source code is because the source code is literaly this:
#include <cstdlib>
#include <iostream>


using namespace std;

int main(int argc, char *argv[])
{
cout << "hi \n";
system("PAUSE");
return EXIT_SUCCESS;
}


The problem is that this won't show the words "hi". They used to show the words, but then I compiled the program with winsock2. Even though winsock2 is no longer there. The problem still persists.

Share this post


Link to post
Share on other sites
The problem, it seems, has nothing to do with my code. When I compile with a header, it causes a bug. When I recompile without the header, the bug remains and doesn't go away. The header, winsock2, is causing a permanent change to my project and my compiler. Once I compile I can't ctrl-z and undo my change, the problem stays there for every future compile.

Share this post


Link to post
Share on other sites

And what compiler are you using?


First I was using vc++. The program I showed earlier was made using dev to see if changing compilers would fix the problem.

Share this post


Link to post
Share on other sites
It sounds like you've modified your project to be a Win32 application rather than a console application, in which case it's not created with a console window by default, but will open one when you call system() (Since it invokes the command interpreter).

However, using Winsock has nothing to do with toggling between Win32 / Console applications, and as far as I know, including winsock2.h won't affect the application type (I've used it in console apps countless times without issue).

What version of Visual Studio are you using, and where did winsock2.h come from - was it with the compiler, or did you download e.g. the platform SDK seperately?

Share this post


Link to post
Share on other sites

#include <cstdlib>
#include <iostream>


using namespace std;

int main(int argc, char *argv[])
{
cout << "hi \n";
system("PAUSE");
return EXIT_SUCCESS;
}


The problem is that this won't show the words "hi". They used to show the words, but then I compiled the program with winsock2. Even though winsock2 is no longer there. The problem still persists.


It's probably the case that your cout stream is not being flushed. Try printing to cerr instead, and try using std::endl instead of embedding a "\n" character -- Windows end line may not be \n alone.

Another option is that you're building as a "win32 application" rather than a "console application" -- check your linker settings.

Finally, console applications have to be started from the console/command line, rather than from within the debugger or the Explorer. Else they won't have the proper interactive TTY setup. (This is an oversimplification -- but for now, do it that way or you'll go crazy!)


This has nothing to do with networking, btw.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!