socket class !!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <WinSock2.h>
#include <WinSock.h>
#include <process.h>
#include <time.h>
#include <iostream>
using namespace std;


class PoPSocket
{
public:
	void Socket()
	{
	const int iReqWinsockVer = 2;   // Minimum winsock version required
	WSAData wsaData;
	if (WSAStartup(MAKEWORD(iReqWinsockVer,0), &wsaData)==0)
	{
		// Check if major version is at least iReqWinsockVer
		if (LOBYTE(wsaData.wVersion) >= iReqWinsockVer)
		{
			SOCKET hSocket;
			hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
			if (hSocket==INVALID_SOCKET)
			{
				// error handling code
				MessageBox(0,"Invaild Socket Handler",0,MB_ICONERROR);
				closesocket(hSocket);
			}
			else
			{
				struct sockaddr
				{
					u_short    sa_family;
					char       sa_data[14];
				};
				struct sockaddr_in
				{
					short   sin_family;
					u_short sin_port;
					struct  in_addr sin_addr;
					char    sin_zero[8];
				};
				// Convert a u_short from host to TCP/IP network byte order.
				u_short htons(u_short hostshort);

			}
		}
		else
		{
			// Required version not available
			MessageBox(0,"Required version of WinSoc not available",0,MB_ICONERROR);
		}
			// Cleanup winsock
		if (WSACleanup()!=0)
		{
			// cleanup failed
			MessageBox(0,"Winsoc cleanup failed",0,MB_ICONERROR);
		}
	}
	else
	{
		MessageBox(0,"Socket startup failed!",0,MB_ICONERROR);
	}
	}
};


so i can call it in the main.cpp as

1
2
PoPSocket soc;
soc.Socket();


but Errors keep pop up


Error	1	error C2373: 'htons' : redefinition; different type modifiers	
	2	IntelliSense: linkage specification is incompatible with previous "htons" (declared at line 1760 of "C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\WinSock2.h")

can someone help me please
Don't include Winsock.h and Winsock2.h. Use one or the other.
the same prob nothing changed
You have a set of definitions in the guts of some nested if statement. Why?

Anyway, that's the problem.
Topic archived. No new replies allowed.