Documentation - PasanBhanu/tcp-asynchronous-client GitHub Wiki
Download
You can download the release binaries from release page or via nuget.
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());
}
}