https://github.com/pasanbhanu/tcp-asynchronous-client
TCP Asynchronous Client DLL for C#. Send and Receive Data with TCP Server Asynchronously in C# Applications
https://github.com/pasanbhanu/tcp-asynchronous-client
async asynchronous-programming csharp tcp-client tcp-socket
Last synced: about 1 month ago
JSON representation
TCP Asynchronous Client DLL for C#. Send and Receive Data with TCP Server Asynchronously in C# Applications
- Host: GitHub
- URL: https://github.com/pasanbhanu/tcp-asynchronous-client
- Owner: PasanBhanu
- License: mit
- Created: 2019-11-28T09:22:53.000Z (over 5 years ago)
- Default Branch: update
- Last Pushed: 2019-12-02T07:12:37.000Z (over 5 years ago)
- Last Synced: 2025-05-06T20:55:54.434Z (about 1 month ago)
- Topics: async, asynchronous-programming, csharp, tcp-client, tcp-socket
- Language: C#
- Homepage:
- Size: 48.8 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
![]()
[](https://github.com/PasanBhanu/tcp-asynchronous-client/issues)
[](https://www.nuget.org/packages/TCPAsynchronousClient)
[](https://github.com/PasanBhanu/tcp-asynchronous-client)
[](https://www.nuget.org/packages/TCPAsynchronousClient)# 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
````c#
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
````c#
private void OnConnect(bool status)
{
Console.WriteLine("Connection Status : " + status.ToString());
}
````#### Setup Data Recieved Callback Function
````c#
private void OnRecieved(string data)
{
Console.WriteLine("Recieved Data : " + data);
}
````### Write to TCP
````c#
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](https://hercules-setup.soft32.com/) to create TCP server in Local Machine with few clicks. Here is an example.
## 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](https://github.com/PasanBhanu/TCPAsynchronousClient/blob/master/LICENSE) for more information.