main.cpp
Expand|Select|Wrap|Line Numbers
- #include "main.h"
- CNetwork net;
- int main()
- {
- int on = 0;
- int command;
- while(on == 0)
- {
- printf("press 1 to connect to network, 2 to display socket,3 to exit.");
- cin >> command;
- if(command == 1)
- {
- net.startupClient();
- }//end if startupclient
- if(command == 2)
- {
- net.printSocket();
- }//end if printsocket
- else
- {
- on = 1;
- }//end else
- }//end while on
- return 0;
- }//end main
Expand|Select|Wrap|Line Numbers
- #ifndef _MAIN_H
- #define _MAIN_H
- //defines
- #define _CRT_SECURE_NO_DEPRECATE
- //includes
- #include <iostream>
- #include <winsock2.h>
- #include <stdio.h>
- #include "network.h"
- //librarys
- #pragma comment(lib, "ws2_32.lib")
- //declare
- //namespaces
- using std::cout;
- using std::endl;
- using std::cin;
- #endif
Expand|Select|Wrap|Line Numbers
- #ifndef _NETWORK_H
- #define _NETWORK_H
- #include "main.h"
- class CNetwork
- {
- public:
- void startupClient();
- void printSocket();
- private:
- void shutdownClient(int *mySocket);
- int *mySocket;
- };
- #endif
Expand|Select|Wrap|Line Numbers
- #include "main.h"
- void CNetwork::startupClient()
- {
- int error;
- WSAData wsaData;
- error = WSAStartup(MAKEWORD(2,2), &wsaData);
- if(error == SOCKET_ERROR)
- {
- printf("Could Not Start Up WinSock!\n");
- }
- printf("WinSocket started\n");
- int mySocket;
- mySocket = socket(AF_INET, SOCK_STREAM, 0);
- &mySocket;
- if(mySocket == SOCKET_ERROR)
- {
- printf("Error Opening Socket!\n");
- }
- printf("Socket Opened!\n");
- //shutdownClient(&mySocket); //DEBUG ONLY
- }//end startnetwork
- void CNetwork::printSocket();
- {
- printf(*mySocket);
- }//end printsocket
- void CNetwork::shutdownClient(int *mySocket)
- {
- printf("Closing Socket: %i\n", *mySocket);
- closesocket(*mySocket);
- printf("Socket Closed\n");
- }//end shutdownnetwork
network.cpp(25) : error C2761: 'void CNetwork::printSocket(void)' : member function redeclaration not allowed
Any help would be awsome!