-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
95 lines (89 loc) · 1.98 KB
/
main.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "Network.hpp"
#include "IPv4.hpp"
#include "SocketIPv4.hpp"
#include <iostream>
DCB dcb;
using namespace Tool::Network;
using namespace std;
void test()
{
char c;
SocketIPv4 sock(ipv4, Socket::stream, Socket::tcp);
std::cout << "Choose mode" << endl;
c = std::cin.get();
switch (c)
{
case 's':
cout << "Server" << endl;
if (sock.GetSocket() == INVALID_SOCKET)
cout << "Invalid Socket!" << endl;
sock.Bind(IPv4::any(), 40942);
sock.Listen();
try
{
sock.Accept(true);
cout << "Connected" << endl;
}
catch (...)
{
switch (WSAGetLastError())
{
case WSANOTINITIALISED:
cout << "WSA Not initialised!" << endl;
break;
case WSAECONNRESET:
cout << "WSA Connection Reset!" << endl;
break;
case WSAEFAULT:
cout << "WSA Fault!" << endl;
break;
case WSAEINTR:
cout << "WSA Blocked!" << endl;
break;
case WSAEINVAL:
cout << "WSA no listen!" << endl;
break;
case WSAEINPROGRESS:
cout << "WSA in progress!" << endl;
break;
case WSAEMFILE:
cout << "WSA M File!" << endl;
break;
case WSAENETDOWN:
cout << "WSA Network Subsystem!" << endl;
break;
case WSAENOBUFS:
cout << "WSA No Buffer!" << endl;
break;
case WSAENOTSOCK:
cout << "WSA Not a socket!" << endl;
break;
case WSAEOPNOTSUPP:
cout << "WSA Not supportet!" << endl;
break;
case WSAEWOULDBLOCK:
cout << "WSA Non Blocking!" << endl;
break;
default:
cout << "Another Error!" << endl;
}
}
break;
case 'c':
cout << "Client" << endl;
if (sock.Connect(IPv4("127.0.0.1"), 40942))
cout << "Fail to connect!" << endl;
cout << WSAGetLastError() << endl;
}
}
int main(int argc, char* argv[])
{
uint8_t ip3[] = { 127, 0, 0, 1 };
IPv4 ip("127.0.0.1");
IPv4 ip2(ip3);
IPv4 ip4 = IPv4::any();
cout << hex << ip.data() << endl;
cout << hex << ip2.data() << endl;
cin.get();
return 0;
}