Internet sockets learning question (Beej's guide)

Mar 16, 2015 at 3:20pm
Greetings all

I would like to learn about network programming in C++. After some searching I find most recommendations for the Beej's Guide (http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html).

Although I will switch to Linux at some point, I am using Windows now. So considering that, is this guide appropriate for me to learn and apply the code in programs I make?

There is a section on Windows users in the guide, and information seems quite straightforward. But since I'm a beginner there maybe some other tricks I should know about.

Thank you,
T
Last edited on Mar 16, 2015 at 3:23pm
Mar 16, 2015 at 4:24pm
No it isn't, not if you're a Windows user. Mainly for the reason that he is telling you to use the first version of the Winsock library which has been depreciated and replaced with Winsock2. Any one of the tutorials here would be better for your needs right now: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740632(v=vs.85).aspx

To be honest, there shouldn't be that large of a difference between socket programming in *nix and Windows. They are both based on the Berkley sockets library, so any changes should be mainly in the specific syntax and a few design considerations.
Mar 16, 2015 at 4:30pm
> I am using Windows now.
> So considering that, is this guide appropriate for me to learn and apply the code in programs I make?


Yes. Except that the examples that use fork() would need changes.
Mar 16, 2015 at 5:04pm
Thank you for answers. I am using CodeBlocks IDE and was hoping to find a way to learn network programming, which would be as cross-platform as possible, with not too many changes required for switching from Windows to Linux. And also with enough good learning materials available.

Last edited on Mar 16, 2015 at 5:04pm
Mar 16, 2015 at 5:17pm
The CodeBlocks IDE can be configured to use the Cygwin compiler.
http://wiki.codeblocks.org/index.php?title=Installing_Cygwin_Compiler
https://cygwin.com/

Note: do not add the suggested compiler switch: -mno-cygwin

This should allow the code in Beej's Guide to be used verbatim, without changes.
Mar 16, 2015 at 7:52pm
Up to now I used CodeBlocks & MinGW GCC for everything I did (also including wxWidgets and OpenGL). I found online that using Cygwin can cause some licensing issues and also special Cygwin dll needs to be included in projects.

Is there no way around so I could use MinGW with CodeBlocks and Beej's Gude?
Last edited on Mar 16, 2015 at 7:54pm
Mar 16, 2015 at 8:56pm
Don't worry about licensing. I doubt that anything you write today will be used in production code. Learn the ground work first and then go from there.

There is nothing wrong with using Cygwin other then it being one more thing for you to learn and setup*. But if you are dead set against going that route then I'll suggest the tutorials on MSDN again. The only changes that you will have to make are in the naming conventions of the libraries involved. For example: 'Ws2_32.lib' would be 'libWs2_32.a' if you are using MinGW instead of the MSVS compiler (cl.exe). Everything else should work, that is the whole point of MinGW after all.

I'll say again, there is very little difference between the two platforms at this level because they are both based on Berkley sockets. Communication between hosts is essentially done in text and it all has to work together somehow. So there isn't much that can be different between the two.

*: To be honest, you're going to fold and end up setting up Cygwin at some point or another anyway. If not for this project then some other unrelated one. So it may be worth it to go through Cygwin just to get that out of the way now.
Mar 16, 2015 at 9:01pm
Thanks Computergeek01, that was a very informative and straight answer.
Topic archived. No new replies allowed.