Hello all,
I have downloaded Beej's Guide to Network Programming. It is for *nix platforms (it has a way to edit it for windows platforms but they seemed a little complicated). I was wanting to know if there lies any guides designed for Windows platforms.
Any help would be great.
10 replies to this topic
#1
Posted 26 June 2010 - 06:08 PM
|
|
|
#2
Posted 26 June 2010 - 08:05 PM
Depending on how the code was written MS-Windows sockets works very similar to *nix, the main difference is in the header files and libraries. MS-Windows uses winsock2.h and ws2_32.lib. I have a copy of a rather large free library that I got from another site which no longer exists. The source code is portable for both *nix and MS-Windows, and for several different compilers. Included in the library are some socket stuff that you might be interested in seeing. If you want it I'll send it to you -- the zip file is about 2 mg. It even contains and example client/server programs that use sockets.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#3
Posted 26 June 2010 - 09:10 PM
Yeah that sounds great! Thanks. Also, in the guide it says this (just an extract):
Can someone please explain that (it seemed a little confusing at the time).
Quote
This is what you'll have to do (unless you install Cygwin!): first, ignore pretty much all of the
system header files I mention in here. All you need to include is:
library. The code to do that looks something like this:
system header files I mention in here. All you need to include is:
#include <winsock.h>Wait! You also have to make a call to WSAStartup() before doing anything else with the sockets
library. The code to do that looks something like this:
#include <winsock.h>
{
WSADATA wsaData; // if this doesn't work
//WSAData wsaData; // then try this instead
// MAKEWORD(1,1) for Winsock 1.1, MAKEWORD(2,0) for Winsock 2.0:
if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) {
fprintf(stderr, "WSAStartup failed.\n");
exit(1);
}Can someone please explain that (it seemed a little confusing at the time).
#4
Posted 26 June 2010 - 09:36 PM
winsock.h is now replaced by winsock2.h The rest of that mearly initializes the socket library for a specific version of the library. Read the remarks section here
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#5
Posted 26 June 2010 - 09:41 PM
WSAData, without "data" being all capitals, is a struct that contains information about the Windows Socket implementation as noted here: WSADATA Structure (Windows). MAKEWORD is a macro for concatination, but we'll leave that out, it will assign a version number to wsaData.
EDIT: Dragon got to it before me.
EDIT: Dragon got to it before me.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#6
Posted 26 June 2010 - 10:07 PM
It also says to initialise WSACleanup() after the sockets library is done with, does that mean at the end of the program?
Also, would work in C++ as well? (fprintf and exit(1) seemed like C code).
Also, would work in C++ as well? (fprintf and exit(1) seemed like C code).
#7
Posted 26 June 2010 - 10:19 PM
Those functions are both valid in C++. You'd ideally call WSACleanup() after you do not require the socket to send or recieve data, if you wish to place it as a destructor in a class or at the end of your program you could fine.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#8
Posted 26 June 2010 - 11:35 PM
Okay, I think I'll research classes for sockets more. Thanks alot Nullw0rm.
#9
Posted 27 June 2010 - 10:14 AM
Hunter100 said:
Okay, I think I'll research classes for sockets more. Thanks alot Nullw0rm.
If you prefer YouTube tutorials, here's one that explains it very well: YouTube - Winsock C++ Tutorial part 1 of 2
“You may be disappointed if you fail, but you are doomed if you don't try.”
- Beverly Sills
- Beverly Sills
#10
Posted 27 June 2010 - 04:13 PM
Thank You also, I was looking for some video tutorials but couldn't find any low enough for me to begin.
#11
Posted 27 June 2010 - 09:01 PM
Hunter100 said:
Thank You also, I was looking for some video tutorials but couldn't find any low enough for me to begin.
You're welcome. :)
“You may be disappointed if you fail, but you are doomed if you don't try.”
- Beverly Sills
- Beverly Sills
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









