Danbias/Code/Network/OysterNetworkServer/ServerMain.cpp

49 lines
723 B
C++
Raw Normal View History

2013-11-18 16:47:57 +01:00
#include <iostream>
#include <WinSock2.h>
#include "Listener.h"
#include "Client.h"
2013-11-18 16:47:57 +01:00
using namespace std;
#pragma comment(lib, "ws2_32.lib")
void ShutdownSockets();
bool InitSockets();
int main()
{
cout << "Server" << endl;
2013-11-18 16:47:57 +01:00
if(!InitSockets())
{
cout << "Sockets failed to initialize" << endl;
}
//Create socket
Listener listener;
listener.Init(9876);
//Start listening
int clientSocket = listener.Accept();
//Accept a client
Client client(clientSocket);
//Send a message to that client
client.Send("asd");
2013-11-18 16:47:57 +01:00
ShutdownSockets();
system("pause");
return 0;
}
bool InitSockets()
{
WSADATA wsaData;
return WSAStartup(MAKEWORD(2, 2), &wsaData) == NO_ERROR;
}
void ShutdownSockets()
{
WSACleanup();
}