Skip to content

Commit 2668e62

Browse files
committed
Work in Networking sample
- Add new socket sample with WiFi version. - Rework code to offer sample with shared code. - Update NuGets.
1 parent 45574e6 commit 2668e62

File tree

8 files changed

+145
-10
lines changed

8 files changed

+145
-10
lines changed

samples/Networking/Networking.sln

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 16
3-
VisualStudioVersion = 16.0.31105.61
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.1.32228.430
44
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Socket.Client", "Socket.Client\Socket.Client.nfproj", "{50F4D87E-CAEE-4D03-A0E8-2109C10EEB6F}"
5+
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Socket.Client", "Socket.Client\Socket.Client.nfproj", "{88AA2FAA-0570-47E2-8866-B36BC8B36A6A}"
6+
EndProject
7+
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Socket.Client_WiFi", "Socket.Client_WiFi\Socket.Client_WiFi.nfproj", "{50F4D87E-CAEE-4D03-A0E8-2109C10EEB6F}"
68
EndProject
79
Global
810
GlobalSection(SolutionConfigurationPlatforms) = preSolution
911
Debug|Any CPU = Debug|Any CPU
1012
Release|Any CPU = Release|Any CPU
1113
EndGlobalSection
1214
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15+
{88AA2FAA-0570-47E2-8866-B36BC8B36A6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{88AA2FAA-0570-47E2-8866-B36BC8B36A6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{88AA2FAA-0570-47E2-8866-B36BC8B36A6A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
18+
{88AA2FAA-0570-47E2-8866-B36BC8B36A6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{88AA2FAA-0570-47E2-8866-B36BC8B36A6A}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{88AA2FAA-0570-47E2-8866-B36BC8B36A6A}.Release|Any CPU.Deploy.0 = Release|Any CPU
1321
{50F4D87E-CAEE-4D03-A0E8-2109C10EEB6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1422
{50F4D87E-CAEE-4D03-A0E8-2109C10EEB6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
1523
{50F4D87E-CAEE-4D03-A0E8-2109C10EEB6F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU

samples/Networking/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
# Networking sample pack
22

3+
Shows how to use network Sockets API.
4+
5+
## Samples
6+
7+
- [Socket Client](Socket.Client/)
8+
- [Socket Client (Wi-Fi connection)](Socket.Client_WiFi/)
9+
310
Shows how to use various APIs related with networking.
411

12+
> NOTE: if you're editing the project files, when working with a target with Wi-Fi capabilities, make sure to add `HAS_WIFI` into the DefineConstants, like this:
13+
14+
```text
15+
<DefineConstants>$(DefineConstants);HAS_WIFI;</DefineConstants>
16+
```
17+
18+
> **Note:** This sample is part of a large collection of nanoFramework feature samples.
19+
> If you are unfamiliar with Git and GitHub, you can download the entire collection as a
20+
> [ZIP file](https://github.com/nanoframework/Samples/archive/main.zip), but be
21+
> sure to unzip everything to access any shared dependencies.
22+
<!-- For more info on working with the ZIP file,
23+
> the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq).
24+
> For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center. -->
25+
526
## Hardware requirements
627

728
An hardware device running a nanoFramework image with networking capabilities enabled.
@@ -10,7 +31,7 @@ An hardware device running a nanoFramework image with networking capabilities en
1031

1132
### Reference
1233

13-
- [System.Security.Cryptography.X509Certificates](http://docs.nanoframework.net/api/System.Security.Cryptography.X509Certificates.html)
34+
- [System.Net.Sockets](http://docs.nanoframework.net/api/System.Net.Sockets.html)
1435

1536
## Build the sample
1637

samples/Networking/Socket.Client/Program.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace SecureClient
2424
{
2525
public class Program
2626
{
27+
2728
#if HAS_WIFI
2829
private static string MySsid = "ssid";
2930
private static string MyPassword = "password";
@@ -35,14 +36,17 @@ public static void Main()
3536

3637
bool success;
3738
CancellationTokenSource cs = new(60000);
39+
3840
#if HAS_WIFI
39-
success = WiFiNetworkHelper.ConnectDhcp(MySsid, MyPassword, requiresDateTime: true, token: cs.Token);
41+
success = WiFiNetworkHelper.Reconnect();
4042
#else
41-
success = NetworkHelper.SetupAndConnectNetwork(cs.Token, true);
43+
success = NetworkHelper.SetupAndConnectNetwork(cs.Token);
4244
#endif
45+
4346
if (!success)
4447
{
45-
Debug.WriteLine($"{DateTime.UtcNow} Can't get a proper IP address and DateTime, error: {NetworkHelper.Status}.");
48+
Debug.WriteLine($"{DateTime.UtcNow} Can't get a proper IP address, error: {NetworkHelper.Status}.");
49+
4650
if (NetworkHelper.HelperException != null)
4751
{
4852
Debug.WriteLine($"ex: {NetworkHelper.HelperException}");

samples/Networking/Socket.Client/Socket.Client.nfproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
99
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
1010
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11-
<ProjectGuid>50f4d87e-caee-4d03-a0e8-2109c10eeb6f</ProjectGuid>
11+
<ProjectGuid>{88AA2FAA-0570-47E2-8866-B36BC8B36A6A}</ProjectGuid>
1212
<OutputType>Exe</OutputType>
1313
<AppDesignerFolder>Properties</AppDesignerFolder>
1414
<FileAlignment>512</FileAlignment>
@@ -60,4 +60,4 @@
6060
<ProjectConfigurationsDeclaredAsItems />
6161
</ProjectCapabilities>
6262
</ProjectExtensions>
63-
</Project>
63+
</Project>

samples/Networking/Socket.Client/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
<package id="nanoFramework.System.Net" version="1.8.1" targetFramework="netnanoframework10" />
88
<package id="nanoFramework.System.Text" version="1.1.3" targetFramework="netnanoframework10" />
99
<package id="nanoFramework.System.Threading" version="1.0.4" targetFramework="netnanoframework10" />
10-
</packages>
10+
</packages>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("CSharp.BlankApplication")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("CSharp.BlankApplication")]
13+
[assembly: AssemblyCopyright("Copyright © ")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// Version information for an assembly consists of the following four values:
23+
//
24+
// Major Version
25+
// Minor Version
26+
// Build Number
27+
// Revision
28+
//
29+
// You can specify all the values or you can default the Build and Revision Numbers
30+
// by using the '*' as shown below:
31+
// [assembly: AssemblyVersion("1.0.*")]
32+
[assembly: AssemblyVersion("1.0.0.0")]
33+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Label="Globals">
4+
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
5+
</PropertyGroup>
6+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
7+
<PropertyGroup>
8+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
9+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
10+
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<ProjectGuid>50f4d87e-caee-4d03-a0e8-2109c10eeb6f</ProjectGuid>
12+
<OutputType>Exe</OutputType>
13+
<AppDesignerFolder>Properties</AppDesignerFolder>
14+
<FileAlignment>512</FileAlignment>
15+
<RootNamespace>Networking</RootNamespace>
16+
<AssemblyName>Networking_WiFi</AssemblyName>
17+
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
18+
<DefineConstants>$(DefineConstants);HAS_WIFI;</DefineConstants>
19+
</PropertyGroup>
20+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
21+
<ItemGroup>
22+
<Compile Include="..\Socket.Client\Program.cs">
23+
<Link>Program.cs</Link>
24+
</Compile>
25+
<Compile Include="Properties\AssemblyInfo.cs" />
26+
</ItemGroup>
27+
<ItemGroup>
28+
<Reference Include="mscorlib">
29+
<HintPath>..\packages\nanoFramework.CoreLibrary.1.12.0\lib\mscorlib.dll</HintPath>
30+
</Reference>
31+
<Reference Include="nanoFramework.Runtime.Events">
32+
<HintPath>..\packages\nanoFramework.Runtime.Events.1.10.0\lib\nanoFramework.Runtime.Events.dll</HintPath>
33+
</Reference>
34+
<Reference Include="nanoFramework.System.Text">
35+
<HintPath>..\packages\nanoFramework.System.Text.1.1.3\lib\nanoFramework.System.Text.dll</HintPath>
36+
</Reference>
37+
<Reference Include="System.Device.WiFi">
38+
<HintPath>..\packages\nanoFramework.System.Device.WiFi.1.4.0\lib\System.Device.WiFi.dll</HintPath>
39+
</Reference>
40+
<Reference Include="System.IO.Streams">
41+
<HintPath>..\packages\nanoFramework.System.IO.Streams.1.0.0\lib\System.IO.Streams.dll</HintPath>
42+
</Reference>
43+
<Reference Include="System.Net">
44+
<HintPath>..\packages\nanoFramework.System.Net.1.8.1\lib\System.Net.dll</HintPath>
45+
</Reference>
46+
<Reference Include="System.Threading">
47+
<HintPath>..\packages\nanoFramework.System.Threading.1.0.4\lib\System.Threading.dll</HintPath>
48+
</Reference>
49+
</ItemGroup>
50+
<ItemGroup>
51+
<None Include="packages.config" />
52+
</ItemGroup>
53+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
54+
<ProjectExtensions>
55+
<ProjectCapabilities>
56+
<ProjectConfigurationsDeclaredAsItems />
57+
</ProjectCapabilities>
58+
</ProjectExtensions>
59+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnanoframework10" />
4+
<package id="nanoFramework.Runtime.Events" version="1.10.0" targetFramework="netnanoframework10" />
5+
<package id="nanoFramework.System.Device.WiFi" version="1.4.0" targetFramework="netnanoframework10" />
6+
<package id="nanoFramework.System.IO.Streams" version="1.0.0" targetFramework="netnanoframework10" />
7+
<package id="nanoFramework.System.Net" version="1.8.1" targetFramework="netnanoframework10" />
8+
<package id="nanoFramework.System.Text" version="1.1.3" targetFramework="netnanoframework10" />
9+
<package id="nanoFramework.System.Threading" version="1.0.4" targetFramework="netnanoframework10" />
10+
</packages>

0 commit comments

Comments
 (0)