123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using Team.Communicate.Data;
- using Team.Communicate.EventArg;
- namespace Team.Communicate.Interfaces
- {
- public interface IAsyncTcpClient : IDisposable
- {
- bool IsAutoConnect { get; set; }
- Encoding Encoding { get; set; }
- IPAddress RemoteIpAddress { get; set; }
- int Port { get; }
- bool IsConnected { get; }
- /// <summary>
- /// 连接成功为true
- /// </summary>
- /// 1.exception ArgumentOutOfRangeException
- /// 2.exception ArgumentNullException
- /// <returns></returns>
- bool Connect();
- /// <summary>
- /// 异步连接成功为true
- /// </summary>
- /// 1.exception ArgumentOutOfRangeException
- /// 2.exception ArgumentNullException
- /// <returns></returns>
- Task<bool> ConnectAsync();
- /// <summary>
- /// 异步发送
- ///1.Exception 未连接异常
- /// </summary>
- /// <param name="msg"></param>
- TransmissionResult SendString(string msg);
- /// <summary>
- /// 异步发送
- ///1.Exception 未连接异常
- /// </summary>
- /// <param name="msg"></param>
- Task<TransmissionResult> SendStringAsync(string msg);
- /// <summary>
- /// 发送并接收一个消息
- /// </summary>
- /// <param name="msg"></param>
- /// <returns></returns>
- string SendAndReceiveString(string msg);
- /// <summary>
- /// 异步发送并接收一个消息
- /// </summary>
- /// <param name="msg"></param>
- /// <returns></returns>
- Task<string> SendAndReceiveStringAsync(string msg);
- /// <summary>
- /// 设定RemoteIp和端口,如果已经连接并且端口和Ip发送变化将断开连接
- /// </summary>
- /// <param name="ip">ip地址</param>
- /// <param name="port">端口</param>
- /// <exception cref="ArgumentNullException"></exception>
- /// <exception cref="FormatException"></exception>
- void SetRemoteIpOrPort(string ip, int port);
- /// <summary>
- /// 异步发送
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- TransmissionResult SendBytes(byte[] data);
-
- /// <summary>
- /// 异步发送
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- Task<TransmissionResult> SendBytesAsync(byte[] data);
- /// <summary>
- /// 异步接收
- /// </summary>
- /// <returns></returns>
- Task<string> ReceiveStringAsync();
- /// <summary>
- /// 异步接收
- /// </summary>
- /// <returns></returns>
- string ReceiveString();
- /// <summary>
- /// 异步接收字节
- /// </summary>
- /// <returns></returns>
- Task<byte[]> ReceiveBytesAsync();
- /// <summary>
- /// 接收字节
- /// </summary>
- /// <returns></returns>
- byte[] ReceiveBytes();
- void DisConnect();
- /// <summary>
- /// tcp状态改变事件
- /// </summary>
- event EventHandler<TcpClientStatusEventArgs> StatusChanged;
- /// <summary>
- /// tcp获取数据事件
- /// </summary>
- event EventHandler<ReceivedEventArgs> Received;
- event EventHandler<SentEventArgs> Sent;
- void Reconnect();
- bool Connecting { get; }
- }
- }
|