Last active
August 29, 2015 14:09
-
-
Save kennykerr/b72da78a04b0c2954ba4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pch.h" | |
#include <conio.h> | |
using namespace Modern; | |
using namespace Windows::Foundation; | |
using namespace Windows::Networking; | |
using namespace Windows::Networking::Sockets; | |
int main() | |
{ | |
Initialize(); | |
StreamSocket socket; | |
HostName hostname(L"moderncpp.com"); | |
socket.ConnectAsync(hostname, L"80"). | |
Completed([](IAsyncAction const & sender, AsyncStatus) | |
{ | |
try | |
{ | |
sender.GetResults(); // Will throw on failure to connect! | |
// Use this to avoid exception: HRESULT hr = sender->abi_GetResults(); | |
printf("Connected!\n"); | |
} | |
catch (Exception const & e) | |
{ | |
MODERN_ASSERT(e.Result == HRESULT_FROM_WIN32(WSAHOST_NOT_FOUND)); | |
printf("Failed 0x%X\n", e.Result); | |
} | |
}); | |
_getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment