-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestHttp.cpp
More file actions
58 lines (47 loc) · 1.55 KB
/
TestHttp.cpp
File metadata and controls
58 lines (47 loc) · 1.55 KB
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
// Copyright 2015, The maxSocket Contributors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <maxSocket/SocketSystem.hpp>
#include <iostream>
#include <vector>
#include <memory>
#include <maxSocket/IP/Address.hpp>
#include <maxSocket/Socket.hpp>
#include <maxSocket/Protocol.hpp>
int main()
{
auto SocketSystem = std::unique_ptr< maxSocket::SocketSystem >{};
auto CreateSocketSystemResult = maxSocket::SocketSystem::CreateSocketSystem( SocketSystem );
if( CreateSocketSystemResult != maxSocket::CreateSocketSystemResults::Success )
{
std::cout << "Error\n";
return -1;
}
auto EndPoints = maxSocket::v0::IP::Addresses{};
auto ResolveHostNameResults = SocketSystem->ResolveHostNameUsingOSDefaults( "google.com", maxSocket::AddressFamily::IPv4, EndPoints );
if( ResolveHostNameResults != maxSocket::ResolveHostNameResults::Success )
{
std::cout << "Error\n";
return -1;
}
if( EndPoints.begin() == EndPoints.end() )
{
std::cout << "Error\n";
return -1;
}
{
// Make a nested scope because the socket should be destroyed before the socket system is
auto FirstEndPoint = * EndPoints.begin();
auto Socket = std::unique_ptr< maxSocket::Socket >{};
auto CreateSocketResult = SocketSystem->CreateSocketAndConnect( FirstEndPoint, 80, maxSocket::Protocol::TCP, Socket );
if( CreateSocketResult != maxSocket::CreateSocketAndConnectResults::Success )
{
std::cout << "Error\n";
return -1;
}
// GET / HTTP/1.1
// Host: www.google.com
//
}
return 0;
}