Skip to content

Commit

Permalink
Add a simple client program using a multibyte build and without MFC t…
Browse files Browse the repository at this point in the history
…o demonstrate the minimum requirements for calling SSLClient.
  • Loading branch information
david-maw committed Nov 30, 2019
1 parent e76d527 commit d938022
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Samples/SimpleClient/SimpleClient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <Windows.h>
#include <memory>
#include <iostream>

#include "EventWrapper.h"

// These are included so the headers below will compile
#include <atltime.h> // for CTime used compiling sslclient.h
#include <WinSock2.h> // For SOCKET used compiling ActiveSock.h

#include "sslclient.h"
#include "ActiveSock.h"

using namespace std;

// This is a simple example using SSLClient with a minimum of dependencies
// It connects to a web server, exchanges a couple of messages, then exits
// it works as a 32 or 64 bit build, with Unicode ar Multibyte characters
// note that the multibyte build uses a UNICODE (wide character) build of
// SSLClient (in the SSLClient.lib file)
int main()
{
wstring HostName(L"www.google.com");
int Port = 443;

CEventWrapper ShutDownEvent;

auto pActiveSock = make_unique<CActiveSock>(ShutDownEvent);
pActiveSock->SetRecvTimeoutSeconds(30);
pActiveSock->SetSendTimeoutSeconds(60);
wcout << "StreamClient connecting to " << HostName.c_str() << ":" << Port << endl;
bool b = pActiveSock->Connect(HostName.c_str(), static_cast<USHORT>(Port));
if (b)
{
// Drive the server side by sending messages it expects
cout << "Socket connected to server, initializing SSL" << endl;
auto pSSLClient = make_unique<CSSLClient>(pActiveSock.get());
HRESULT hr = pSSLClient->Initialize(HostName.c_str());
if (SUCCEEDED(hr))
{
cout << "Connected, cert name matches=" << pSSLClient->getServerCertNameMatches()
<< ", cert is trusted=" << pSSLClient->getServerCertTrusted() << endl;
cout << "Sending greeting" << endl;
string msg("GET HTTP/1.1\n"); // Minimum needed to get a response from a web server
if (pSSLClient->Send(msg.c_str(), msg.length()) != msg.length())
cout << "Wrong number of characters sent" << endl;
cout << "Listening for message from server" << endl;
int len = 0;
char Msg[100];
if (0 < (len = pSSLClient->Recv(Msg, sizeof(Msg))))
{
cout << "Received '" << string(Msg, len) << "'" << endl;
cout << "Shutting down" << endl;
}
else
cout << "Recv reported an error" << endl;
}
else
{
wcout << L"SSL client initialize failed" << endl;
}
pActiveSock->Disconnect();
}
else
{
cout << "Socket failed to connect to server" << endl;
}
cout << "Press enter when finished" << endl;
if (getchar()) 0; // The fake test is to avoid a compiler warning for ignoring the result
return 0;
}
172 changes: 172 additions & 0 deletions Samples/SimpleClient/SimpleClient.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>SimpleClient</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\SSLClient\Include;..\..\Common\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\SSLClient\Include;..\..\Common\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\SSLClient\Include;..\..\Common\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\SSLClient\Include;..\..\Common\Include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="SimpleClient.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\SSLClient\Include\EventWrapper.h" />
<ClInclude Include="..\SSLClient\Include\SSLClient.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SSLClient\SSLClient.vcxproj">
<Project>{71d079b7-91c6-4ca2-8bfe-e369835da8f3}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
33 changes: 33 additions & 0 deletions Samples/SimpleClient/SimpleClient.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Header Files\SSLClientLib Headers">
<UniqueIdentifier>{edfdee1b-e7cb-4923-8f53-8e98c8896f69}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="SimpleClient.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\SSLClient\Include\EventWrapper.h">
<Filter>Header Files\SSLClientLib Headers</Filter>
</ClInclude>
<ClInclude Include="..\SSLClient\Include\SSLClient.h">
<Filter>Header Files\SSLClientLib Headers</Filter>
</ClInclude>
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions StreamSSL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StreamServer", "Samples\Str
{287B68D2-7381-4E78-AC72-79A49738228D} = {287B68D2-7381-4E78-AC72-79A49738228D}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleClient", "Samples\SimpleClient\SimpleClient.vcxproj", "{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down Expand Up @@ -58,13 +60,22 @@ Global
{6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Release|Win32.Build.0 = Release|Win32
{6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Release|x64.ActiveCfg = Release|x64
{6FC978B9-9CC8-4C8A-A5E3-D575B59ED415}.Release|x64.Build.0 = Release|x64
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug|Win32.ActiveCfg = Debug|Win32
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug|Win32.Build.0 = Debug|Win32
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug|x64.ActiveCfg = Debug|x64
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Debug|x64.Build.0 = Debug|x64
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Release|Win32.ActiveCfg = Release|Win32
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Release|Win32.Build.0 = Release|Win32
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Release|x64.ActiveCfg = Release|x64
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{144CCC0E-0CE9-42D2-887B-4210DEAA2BC6} = {1CB7EA77-6290-4FCE-A1F9-FA162C4562F8}
{6FC978B9-9CC8-4C8A-A5E3-D575B59ED415} = {1CB7EA77-6290-4FCE-A1F9-FA162C4562F8}
{A96158C0-9879-4D2C-BBE6-ED2B86A1E93E} = {1CB7EA77-6290-4FCE-A1F9-FA162C4562F8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E2735530-C231-462D-AFF1-BD154690364B}
Expand Down

0 comments on commit d938022

Please sign in to comment.