Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennykerr/b72da78a04b0c2954ba4 to your computer and use it in GitHub Desktop.
Save kennykerr/b72da78a04b0c2954ba4 to your computer and use it in GitHub Desktop.
#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