-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSocket.cpp
More file actions
48 lines (39 loc) · 949 Bytes
/
Socket.cpp
File metadata and controls
48 lines (39 loc) · 949 Bytes
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
#include "stdafx.h"
#include "Socket.h"
#include <iostream>
Socket::Socket()
{
memset(&m_Addr, 0, sizeof(m_Addr));
}
void Socket::setServerIP(LPCSTR lpszHostIP)
{
m_Addr.sin_addr.s_addr = inet_addr(lpszHostIP);
}
void Socket::setPort(USHORT wPort)
{
m_Addr.sin_port = htons(wPort);
}
void Socket::setSocketType(USHORT wFamilySocket)
{
m_Addr.sin_family = wFamilySocket;
}
void Socket::setConnection(int nSocketType, int nType, int nProtocol)
{
m_Connection = socket(nSocketType, nType, nProtocol);
}
void Socket::delete_descriptor() {
closesocket(m_Connection);
WSACleanup();
}
int Socket::Connect()
{
return connect(m_Connection, (SOCKADDR*)&m_Addr, sizeof(m_Addr));
}
int Socket::Recv(char* buf, int length)
{
return recv(m_Connection, buf, length, NULL);
}
int Socket::Send(std::vector<unsigned char> packet)
{
return send(m_Connection, (char*)&packet[0], packet.size(), NULL);
}