55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#include "connector.h"
|
|
|
|
Connector::Connector() {}
|
|
|
|
Connector::~Connector() {}
|
|
|
|
int Connector::Init() {
|
|
#ifdef _WIN32
|
|
if (WSAStartup(MAKEWORD(2, 2), &m_wsaData) != 0) { /* Initialisation de l'environnement reseau (Windows only) */
|
|
std::cout << "Initialisation WinSock." << std::endl;
|
|
return 1;
|
|
}
|
|
#endif
|
|
|
|
m_sock_udp = socket(AF_INET, SOCK_DGRAM, 0);
|
|
if (m_sock_udp == INVALID_SOCKET) { /* Creation du socket UDP */
|
|
std::cout << "Creation Socket UDP." << std::endl;
|
|
return 2;
|
|
}
|
|
|
|
m_sock_tcp = socket(AF_INET, SOCK_STREAM, 0);
|
|
if (m_sock_tcp == INVALID_SOCKET) { /* Creation du socket TCP */
|
|
std::cout << "Creation Socket TCP." << std::endl;
|
|
return 3;
|
|
}
|
|
|
|
/* Creation structure donnes descripteur du socket serveur */
|
|
sockaddr_in addr;
|
|
addr.sin_family = AF_INET;
|
|
addr.sin_port = htons(SRV_PORT);
|
|
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
if (bind(m_sock_udp, (sockaddr*)&addr, sizeof(addr)) != 0) { /* Associer le socket UDP au port */
|
|
std::cout << "Association Socket UDP." << std::endl;
|
|
return 4;
|
|
}
|
|
|
|
if (bind(m_sock_tcp, (sockaddr*)&addr, sizeof(addr)) != 0) { /* Associer le socket TCP au port */
|
|
std::cout << "Association Socket TCP." << std::endl;
|
|
return 5;
|
|
}
|
|
|
|
std::cout << "It is the voork!" << std::endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int Connector::Connect(sockaddr_in srv_addr, std::string name) {
|
|
return 0;
|
|
}
|
|
|
|
UINT64 Connector::getId() const { return m_sid; }
|
|
|
|
unsigned int Connector::getSeed() const { return m_seed; }
|