Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For .NET Core, TcpClient doesn't support the .Connect() API #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions EasyModbusTCPCore/ModbusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Reflection;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace EasyModbus
{
Expand Down Expand Up @@ -73,13 +74,13 @@ public ModbusClient()
/// <summary>
/// Establish connection to Master device in case of Modbus TCP. Opens COM-Port in case of Modbus RTU
/// </summary>
public void Connect()
public async Task ConnectAsync()

Choose a reason for hiding this comment

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

I would suggest to add CancellationToken support to Async Methods and also to evaluat it as well and do not trust the third party is doing it.

{

if (debug) StoreLogData.Instance.Store("Open TCP-Socket, IP-Address: " + ipAddress + ", Port: " + port, System.DateTime.Now);
tcpClient = new TcpClient();

var result = tcpClient.ConnectAsync(ipAddress, port);
await tcpClient.ConnectAsync(ipAddress, port);


//tcpClient = new TcpClient(ipAddress, port);
Expand All @@ -91,13 +92,13 @@ public void Connect()
/// <summary>
/// Establish connection to Master device in case of Modbus TCP.
/// </summary>
public void Connect(string ipAddress, int port)
public async Task ConnectAsync(string ipAddress, int port)
{

if (debug) StoreLogData.Instance.Store("Open TCP-Socket, IP-Address: " + ipAddress + ", Port: " + port, System.DateTime.Now);
tcpClient = new TcpClient();

var result = tcpClient.ConnectAsync(ipAddress, port);
await tcpClient.ConnectAsync(ipAddress, port);


//tcpClient = new TcpClient(ipAddress, port);
Expand Down