Network Programming from First Princliples
From C4 Engine Wiki
This article is for people interesting in the kind of code that the C4 Engine takes care of, behind the scenes, when it comes to network programming. This article is about getting sample client and server network (socket) code compiled in your Visual C++ 2008 Express Edition environment.
The code can be found at this link:
http://thedefaced.org/tutorials/C_Winsock_Tutorial_Mulciber.htm
Within Visual Studio 2008 Express Edition, for both client and server, use File| New | Project to create 2 new, Win32 console application, empty projects - call them say socket_client and socket_server. Then for each, just right click on source files in the Solution Exporer, and then Add new item, cpp file - call them client.cpp and server.cpp respectively. Then just add the tutorial code and you have the basics for a chat application from first princliples.
You might want to add a couple of lines at the end like
int testVar = 0; std::cin >> testVar;
to prevent the console from disappearing when you are testing it.
You can start two instances of Visual C++ 2008 to run the server (listener) first and then connect with the client.
Don't forget to add this library to your linker settings - ws2_32.lib. To do so, right click on the project in the solution explorer, then select properties. Then, below the Configuration Properties section, go to Linker then Input and then Additional Dependencies. That's where you add ws2_32.lib.
Also, the steps outlined at this next link provide a very high-level summary how to use C++ sockets, even if the article is intended primarily for a unix audience:
http://sage.mc.yu.edu/kbeen/teaching/networking/resources/sockets.html
Just scroll down to the heading "The TCP Server".
--Jimbobjames 04 May 2008
