Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion SimpleTCP/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion SimpleTCP/SimpleTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as .NET's TcpClient is not interfaced, ISimpleTcpClient won't help to mock Connected property.

void Write(byte[] data);
void Write(string data);
Message WriteLineAndGetReply(string data, TimeSpan timeout);
}

public class SimpleTcpClient : ISimpleTcpClient
{
public SimpleTcpClient()
{
Expand Down
23 changes: 22 additions & 1 deletion SimpleTCP/SimpleTcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TcpClient> ClientConnected;
event EventHandler<TcpClient> ClientDisconnected;
event EventHandler<Message> DelimiterDataReceived;
event EventHandler<Message> DataReceived;
IEnumerable<IPAddress> GetIPAddresses();
List<IPAddress> 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()
{
Expand Down