Skip to content

Commit

Permalink
Merge branch 'master' into NETCore2.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	Tcp.NET.Server/Handlers/TcpHandlerServerBaseTcp.cs
  • Loading branch information
LiveOrDevTrying committed May 30, 2023
2 parents 38fd1ee + ee0a8cb commit 7b20259
Show file tree
Hide file tree
Showing 42 changed files with 886 additions and 844 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Check Markdown links

on: push

jobs:
markdown-link-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: gaurav-nelson/github-action-markdown-link-check@v1
96 changes: 75 additions & 21 deletions README.md

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions Tcp.NET.Client/Handlers/TcpClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ protected override TcpConnectionClientEventArgs CreateConnectionEventArgs(TcpCon
return new TcpConnectionClientEventArgs
{
Connection = args.Connection,
ConnectionEventType = args.ConnectionEventType
ConnectionEventType = args.ConnectionEventType,
CancellationToken = args.CancellationToken
};
}

Expand All @@ -37,7 +38,8 @@ protected override TcpErrorClientEventArgs CreateErrorEventArgs(TcpErrorEventArg
{
Connection = args.Connection,
Exception = args.Exception,
Message = args.Message
Message = args.Message,
CancellationToken = args.CancellationToken
};
}

Expand All @@ -48,7 +50,8 @@ protected override TcpMessageClientEventArgs CreateMessageEventArgs(TcpMessageEv
Bytes = args.Bytes,
Connection = args.Connection,
Message = args.Message,
MessageEventType = args.MessageEventType
MessageEventType = args.MessageEventType,
CancellationToken = args.CancellationToken
};
}
}
Expand Down
199 changes: 105 additions & 94 deletions Tcp.NET.Client/Handlers/TcpClientHandlerBase.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Tcp.NET.Client/ITcpNETClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public interface ITcpNETClient :
TcpErrorClientEventArgs,
ConnectionTcp>
{
bool IsRunning { get; }
}
}
Binary file modified Tcp.NET.Client/Logo.ico
Binary file not shown.
Binary file modified Tcp.NET.Client/Logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions Tcp.NET.Client/Models/IParamsTcpClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using PHS.Networking.Models;

namespace Tcp.NET.Client.Models
{
public interface IParamsTcpClient : IParams
{
byte[] DisconnectBytes { get; }
byte[] EndOfLineBytes { get; }
string Host { get; }
bool IsSSL { get; }
bool OnlyEmitBytes { get; }
byte[] PingBytes { get; }
byte[] PongBytes { get; }
int Port { get; }
byte[] Token { get; }
bool UseDisconnectBytes { get; }
bool UsePingPong { get; }
}
}
59 changes: 2 additions & 57 deletions Tcp.NET.Client/Models/ParamsTcpClient.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using PHS.Networking.Models;
using PHS.Networking.Utilities;
using PHS.Networking.Utilities;
using System;
using System.Linq;
using System.Text;

namespace Tcp.NET.Client.Models
{
public class ParamsTcpClient : Params
public class ParamsTcpClient : IParamsTcpClient
{
public string Host { get; protected set; }
public int Port { get; protected set; }
Expand Down Expand Up @@ -63,59 +61,6 @@ public ParamsTcpClient(string host, int port, string endOfLineCharacters, string
Token = Encoding.UTF8.GetBytes(token);
}

if (UseDisconnectBytes && (DisconnectBytes == null || Statics.ByteArrayEquals(DisconnectBytes, Array.Empty<byte>())))
{
DisconnectBytes = new byte[] { 3 };
}
}
public ParamsTcpClient(string host, int port, byte[] endOfLineBytes, string token = null, bool isSSL = true, bool onlyEmitBytes = true, bool usePingPong = true, byte[] pingBytes = null, byte[] pongBytes = null, bool useDisconnectBytes = true, byte[] disconnectBytes = null)
{
if (string.IsNullOrWhiteSpace(host))
{
throw new ArgumentException("Host is not valid");
}

if (port <= 0)
{
throw new ArgumentException("Port is not valid");
}

if (endOfLineBytes == null || endOfLineBytes.Length <= 0 || Statics.ByteArrayEquals(endOfLineBytes, Array.Empty<byte>()))
{
throw new ArgumentException("End of Line Characters are not valid");
}

if (token != null && string.IsNullOrWhiteSpace(token))
{
throw new ArgumentException("Token is not valid");
}

if (usePingPong && (pingBytes == null || pingBytes.Length <= 0 || Statics.ByteArrayEquals(pingBytes, Array.Empty<byte>())))
{
pingBytes = Encoding.UTF8.GetBytes("ping");
}

if (usePingPong && (pongBytes == null || pongBytes.Length <= 0 || Statics.ByteArrayEquals(pongBytes, Array.Empty<byte>())))
{
pongBytes = Encoding.UTF8.GetBytes("pong");
}

Host = host;
Port = port;
EndOfLineBytes = endOfLineBytes;
UsePingPong = usePingPong;
PingBytes = pingBytes;
PongBytes = pongBytes;
IsSSL = isSSL;
OnlyEmitBytes = onlyEmitBytes;
UseDisconnectBytes = useDisconnectBytes;
DisconnectBytes = disconnectBytes;

if (!string.IsNullOrWhiteSpace(token))
{
Token = Encoding.UTF8.GetBytes(token);
}

if (UseDisconnectBytes && (DisconnectBytes == null || Statics.ByteArrayEquals(DisconnectBytes, Array.Empty<byte>())))
{
DisconnectBytes = new byte[] { 3 };
Expand Down
72 changes: 72 additions & 0 deletions Tcp.NET.Client/Models/ParamsTcpClientBytes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using PHS.Networking.Utilities;
using System;
using System.Linq;
using System.Text;

namespace Tcp.NET.Client.Models
{
public class ParamsTcpClientBytes : IParamsTcpClient
{
public string Host { get; protected set; }
public int Port { get; protected set; }
public byte[] EndOfLineBytes { get; protected set; }
public bool UsePingPong { get; protected set; }
public byte[] PingBytes { get; protected set; }
public byte[] PongBytes { get; protected set; }
public bool IsSSL { get; protected set; }
public bool OnlyEmitBytes { get; protected set; }
public byte[] Token { get; protected set; }
public bool UseDisconnectBytes { get; protected set; }
public byte[] DisconnectBytes { get; protected set; }

public ParamsTcpClientBytes(string host, int port, byte[] endOfLineBytes, byte[] token = null, bool isSSL = true, bool onlyEmitBytes = true, bool usePingPong = true, byte[] pingBytes = null, byte[] pongBytes = null, bool useDisconnectBytes = true, byte[] disconnectBytes = null)
{
if (string.IsNullOrWhiteSpace(host))
{
throw new ArgumentException("Host is not valid");
}

if (port <= 0)
{
throw new ArgumentException("Port is not valid");
}

if (endOfLineBytes == null || endOfLineBytes.Length <= 0 || Statics.ByteArrayEquals(endOfLineBytes, Array.Empty<byte>()))
{
throw new ArgumentException("End of Line Characters are not valid");
}

if (token != null && token.Where(x => x != 0).ToArray().Length <= 0)
{
throw new ArgumentException("Token is not valid");
}

if (usePingPong && (pingBytes == null || pingBytes.Length <= 0 || Statics.ByteArrayEquals(pingBytes, Array.Empty<byte>())))
{
pingBytes = Encoding.UTF8.GetBytes("ping");
}

if (usePingPong && (pongBytes == null || pongBytes.Length <= 0 || Statics.ByteArrayEquals(pongBytes, Array.Empty<byte>())))
{
pongBytes = Encoding.UTF8.GetBytes("pong");
}

Host = host;
Port = port;
EndOfLineBytes = endOfLineBytes;
UsePingPong = usePingPong;
PingBytes = pingBytes;
PongBytes = pongBytes;
IsSSL = isSSL;
OnlyEmitBytes = onlyEmitBytes;
UseDisconnectBytes = useDisconnectBytes;
DisconnectBytes = disconnectBytes;
Token = token;

if (UseDisconnectBytes && (DisconnectBytes == null || Statics.ByteArrayEquals(DisconnectBytes, Array.Empty<byte>())))
{
DisconnectBytes = new byte[] { 3 };
}
}
}
}
13 changes: 11 additions & 2 deletions Tcp.NET.Client/TcpNETClient.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Tcp.NET.Client.Events.Args;
using PHS.Networking.Services;
using Tcp.NET.Client.Events.Args;
using Tcp.NET.Client.Handlers;
using Tcp.NET.Client.Models;
using Tcp.NET.Core.Models;

namespace Tcp.NET.Client
{
public class TcpNETClient :
TcpNETClientBase<
CoreNetworkingClient<
TcpConnectionClientEventArgs,
TcpMessageClientEventArgs,
TcpErrorClientEventArgs,
Expand All @@ -23,5 +24,13 @@ protected override TcpClientHandler CreateTcpClientHandler()
{
return new TcpClientHandler(_parameters);
}

public bool IsRunning
{
get
{
return _handler.IsRunning;
}
}
}
}
92 changes: 0 additions & 92 deletions Tcp.NET.Client/TcpNETClientBase.cs

This file was deleted.

Binary file modified Tcp.NET.Core/Logo.ico
Binary file not shown.
Binary file modified Tcp.NET.Core/Logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions Tcp.NET.Core/Models/ConnectionTcp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using PHS.Networking.Models;
using System;
using System.IO;
using System.Net.Sockets;

namespace Tcp.NET.Core.Models
Expand All @@ -7,5 +9,35 @@ public class ConnectionTcp : IConnection
{
public string ConnectionId { get; set; }
public TcpClient TcpClient { get; set; }
public MemoryStream MemoryStream { get; set; }
public bool Disposed { get; set; }
public bool EndOfLine { get; set; }

public ConnectionTcp()
{
MemoryStream = new MemoryStream();
}

public virtual void Dispose()
{
try
{
TcpClient?.GetStream().Close();
}
catch { }

try
{
TcpClient?.Dispose();
}
catch { }

try
{
MemoryStream.Close();
MemoryStream.Dispose();
}
catch { }
}
}
}
5 changes: 4 additions & 1 deletion Tcp.NET.Server/Events/Args/TcpAuthorizeBaseEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Tcp.NET.Server.Models;
using PHS.Core.Events.Args;

namespace Tcp.NET.Server.Events.Args
{
public class TcpAuthorizeBaseEventArgs<Z, A> : AuthorizeBaseEventArgs<Z>
public class TcpAuthorizeBaseEventArgs<Z, A> : BaseArgs
where Z : IdentityTcpServer<A>
{
public Z Connection { get; set; }
public string Token { get; set; }
}
}

0 comments on commit 7b20259

Please sign in to comment.