diff --git a/SimpleTCP/Message.cs b/SimpleTCP/Message.cs index d9d9a6a..130a84d 100644 --- a/SimpleTCP/Message.cs +++ b/SimpleTCP/Message.cs @@ -7,7 +7,17 @@ namespace SimpleTCP { - public class Message + public interface IMessage + { + byte[] Data { get; } + string MessageString { get; } + void Reply(byte[] data); + void Reply(string data); + void ReplyLine(string data); + TcpClient TcpClient { get; } + } + + public class Message : IMessage { private TcpClient _tcpClient; private System.Text.Encoding _encoder = null; diff --git a/SimpleTCP/SimpleTcpClient.cs b/SimpleTCP/SimpleTcpClient.cs index 5c66a93..f432476 100644 --- a/SimpleTCP/SimpleTcpClient.cs +++ b/SimpleTCP/SimpleTcpClient.cs @@ -9,7 +9,20 @@ namespace SimpleTCP { - public class SimpleTcpClient : IDisposable + public interface ISimpleTcpClient : IDisposable + { + byte Delimiter { get; set; } + Encoding StringEncoder { get; set; } + bool AutoTrimStrings { get; set; } + SimpleTcpClient Connect(string hostNameOrIpAddress, int port); + SimpleTcpClient Disconnect(); + TcpClient TcpClient { get; } + void Write(byte[] data); + void Write(string data); + Message WriteLineAndGetReply(string data, TimeSpan timeout); + } + + public class SimpleTcpClient : ISimpleTcpClient { public SimpleTcpClient() { diff --git a/SimpleTCP/SimpleTcpServer.cs b/SimpleTCP/SimpleTcpServer.cs index 15d1509..b13518d 100644 --- a/SimpleTCP/SimpleTcpServer.cs +++ b/SimpleTCP/SimpleTcpServer.cs @@ -11,7 +11,28 @@ namespace SimpleTCP { - public class SimpleTcpServer + public interface ISimpleTcpServer + { + byte Delimiter { get; set; } + Encoding StringEncoder { get; set; } + bool AutoTrimStrings { get; set; } + event EventHandler ClientConnected; + event EventHandler ClientDisconnected; + event EventHandler DelimiterDataReceived; + event EventHandler DataReceived; + IEnumerable GetIPAddresses(); + List GetListeningIPs(); + void Broadcast(byte[] data); + void Broadcast(string data); + void BroadcastLine(string data); + SimpleTcpServer Start(int port, bool ignoreNicsWithOccupiedPorts = true); + SimpleTcpServer Start(int port, AddressFamily addressFamilyFilter); + SimpleTcpServer Start(IPAddress ipAddress, int port); + void Stop(); + int ConnectedClientsCount { get; } + } + + public class SimpleTcpServer : ISimpleTcpServer { public SimpleTcpServer() {