Skip to content

TCP Asynchronous Client DLL for C#. Send and Receive Data with TCP Server Asynchronously in C# Applications

License

Notifications You must be signed in to change notification settings

PasanBhanu/tcp-asynchronous-client

Repository files navigation

contributions welcome Nuget HitCount Nuget

TCP Asynchronous Client for C#.NET

TCP Asynchronous Client DLL for C#. Communicate with TCP Server in C# Applications. Simple and less resource usage model without multithreading or waitOne().

How To Use

Add the DLL to your project as a reference. Create a TCPAsyncClient Object and use the functions. Complete workable example is given in Sample Application

Constructors

  • public AsynchronousClient(string _ip, int _port)

Functions Available

  • void Connect() - Connect to the server
  • bool Write(string _data) - Send data to server
  • bool Write(byte[] _data) - Send data to server
  • void Dispose() - Dispose socket/ connection
  • void Disconnect() - Disconnect connection
  • bool IsConnected() - Check is the socket connected

Callbacks

  • Connection Status - OnConnectEventHandler -> void OnConnect(bool status)
  • Recieve Data - DataReceivedEventHandler -> void OnRecieved(string data)

How To Use

Create Object

AsynchronousClient tcp = new AsynchronousClient(txtIpAddress.Text, int.Parse(txtPort.Text));
tcp.OnConnectEvent += new AsynchronousClient.OnConnectEventHandler(OnConnect);
tcp.OnDataRecievedEvent += new AsynchronousClient.DataReceivedEventHandler(OnRecieved);
tcp.Connect();

Setup Connection Status Callback Function

private void OnConnect(bool status)
{
    Console.WriteLine("Connection Status : " + status.ToString());
}

Setup Data Recieved Callback Function

private void OnRecieved(string data)
{
    Console.WriteLine("Recieved Data : " + data);
}

Write to TCP

private void WriteData(string data)
{
    try
      {
          if (tcp.Write(data))
          {
              Console.WriteLine("Write OK");
          }
          else
          {
              Console.WriteLine("Write Failed");
          }
      }catch(Exception ex)
      {
          // Catch errors in Sending Data
          Console.WriteLine("Error : " + ex.ToString());
      }
}

Create TCP Server for Testing

You can use Hercules Setup Utility to create TCP server in Local Machine with few clicks. Here is an example.

Hercules TCP Server Sample

Support

This application is developed using .NET Framework 4.6

Download

Please go to release page to download the stable version. We recommend not to use alpha or beta releases for your projects.

Contributing

Contributors are WELCOME!

License

The MIT License (MIT). Please see License File for more information.

About

TCP Asynchronous Client DLL for C#. Send and Receive Data with TCP Server Asynchronously in C# Applications

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages