Skip to content

Conversation

@AdrianSoundy
Copy link
Member

Description

Initial commit of TcpClient & TCpListener

Motivation and Context

How Has This Been Tested?

Pending

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (work on Unit Tests, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@nfbot nfbot added the Type: enhancement New feature or request label Feb 7, 2022
@AdrianSoundy AdrianSoundy merged commit c36b03b into develop Feb 7, 2022

trigger:
- develop
branches:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this pipeline for example, it's up to date: https://github.com/nanoframework/nanoFramework.Azure.Devices/blob/develop/azure-pipelines.yml
The one you are using seems not the latest version.

<Compile Include="Sockets\TcpListener.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib, Version=1.12.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing something in the nuspec:
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the missing System.Net

<tags>nanoFramework C# csharp netmf netnf nanoFramework.System.Net</tags>
<dependencies>
<dependency id="nanoFramework.CoreLibrary" version="1.12.0-preview.5" />
<dependency id="nanoFramework.Runtime.Events" version="1.10.0-preview.6" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing System.Net
Please use the latest yaml template, it will catch it automatically

public Socket Client
{
get => _client;
set => _client = value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there the possibility to bring your own Socket client? This should not be exposed publicly. Especially following the code and the path, client is always inialized while creation the TcpClient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I checked the API in .NET and it's a get; set; so let it be a get; set; then :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to Auto property

/// <returns>The underlying NetworkStream.</returns>
public NetworkStream GetStream()
{
//if (!_client.Connected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove dead code. If you keep dead code, please write why you keep it. In general, in classes like this one, there is no reason ;-) In samples, it can be handy but in all cases, a comment is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look at adding Connected property to Socket first

/// <param name="port">The port number to which you intend to connect.</param>
public void Connect(IPAddress[] address, int port)
{
Connect(new IPEndPoint(address[0], port));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about the logic here?
I think it should be a foreach trying to connect up to the point you manage to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it that way as the Socket class normally does the connect using array
Added foreach loop

}
else
{
Connect(new IPEndPoint(address, port));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the right logic here?
It seems to me that if the client us not null, you'll call again the same function again and again. I must miss something but something seems a bit weird in the logic all up.

Copy link
Member Author

@AdrianSoundy AdrianSoundy Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The break after Connect should take you out of For loop unless Connect fails

{
private Socket _client;
private NetworkStream _stream;
private bool disposedValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_disposed

otherwise it does not follow the naming rules and the Value doesn't bring any value ;-)

@@ -0,0 +1,21 @@
MIT License
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a proper README.md as well with a usage.

@josesimoes josesimoes deleted the Intial_code branch February 23, 2022 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants