Skip to content

Commit

Permalink
Metadata messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloet committed Feb 6, 2020
1 parent d77cc56 commit cbdb8e4
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 134 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ jobs:
with:
dotnet-version: '3.1.100' # SDK Version to use.
- run: dotnet build SimpleSockets --configuration Release
- run: dotnet test Tests/Test.Sockets.Basic --configuration Release
- run: dotnet test Tests/Test.Sockets.Parallel --configuration Release
- run: dotnet test Tests/Test.Sockets.Basic --configuration Release
2 changes: 1 addition & 1 deletion Examples/Console/NetCore.Console.Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private static void ClientOnFileReceiver(SimpleSocketClient a, int currentPart,
WriteLine("File received and stored at location: " + loc);
}

private static void CustomHeader(SimpleSocket a, object msg, IDictionary<object, object> dict)
private static void CustomHeader(SimpleSocket a, object msg, IDictionary<object, object> dict, Type objectType)
{
WriteLine("Test");
// WriteLine("Bytes received from server with header = " + header + " and message = " + msg);
Expand Down
2 changes: 1 addition & 1 deletion Examples/Console/NetCore.Console.Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private static void ListenerOnFileReceiver(IClientInfo client, int currentPart,
WriteLine("File received and stored at location: " + loc);
}

private static void CustomHeaderReceived(IClientInfo client, object msg, IDictionary<object, object> metadata)
private static void CustomHeaderReceived(IClientInfo client, object msg, IDictionary<object, object> metadata, Type objectType)
{
WriteLine("Test");
// WriteLine("The server received a message from the client with ID " + client.Id + " the header is : " + header + " and the message is : " + msg);
Expand Down
6 changes: 3 additions & 3 deletions SimpleSockets/Client/SimpleSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace SimpleSockets.Client

public delegate void MessageReceivedDelegate(SimpleSocketClient client, string msg);

public delegate void MessageWithMetadataReceivedDelegate(SimpleSocketClient client, object message, IDictionary<object,object> metadata);
public delegate void MessageWithMetadataReceivedDelegate(SimpleSocketClient client, object message, IDictionary<object,object> metadata, Type ObjectType);

public delegate void BytesReceivedDelegate(SimpleSocketClient client, byte[] messageBytes);

Expand Down Expand Up @@ -383,9 +383,9 @@ protected internal override void RaiseMessageContractReceived(IClientInfo client
contract.RaiseOnMessageReceived(this, client, contract.DeserializeToObject(data), contract.MessageHeader);
}

protected internal override void RaiseMessageWithMetaDataReceived(IClientInfo client, object message, IDictionary<object,object> metadata)
protected internal override void RaiseMessageWithMetaDataReceived(IClientInfo client, object message, IDictionary<object,object> metadata, Type objectType)
{
MessageWithMetadataReceived?.Invoke(this, message, metadata);
MessageWithMetadataReceived?.Invoke(this, message, metadata, objectType);
}

protected internal override void RaiseBytesReceived(IClientInfo client, byte[] data)
Expand Down
8 changes: 5 additions & 3 deletions SimpleSockets/Client/SimpleSocketTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public override void StartClient(string ipServer, int port, int reconnectInSecon

if (EnableExtendedAuth)
SendAuthMessage();
else
SendBasicAuthMessage();

Endpoint = new IPEndPoint(GetIp(ipServer), port);

Expand Down Expand Up @@ -217,7 +219,7 @@ protected internal override void Receive(IClientMetadata state, int offset = 0)
}
}

protected override async void ReceiveCallback(IAsyncResult result)
protected override void ReceiveCallback(IAsyncResult result)
{
var state = (ClientMetadata)result.AsyncState;

Expand Down Expand Up @@ -247,11 +249,11 @@ protected override async void ReceiveCallback(IAsyncResult result)
{
if (state.SimpleMessage == null)
state.SimpleMessage = new SimpleMessage(state, this, true);
await state.SimpleMessage.ReadBytesAndBuildMessage(receive);
state.SimpleMessage.ReadBytesAndBuildMessage(receive);
}
else if (receive > 0)
{
await state.SimpleMessage.ReadBytesAndBuildMessage(receive);
state.SimpleMessage.ReadBytesAndBuildMessage(receive);
}
}

Expand Down
12 changes: 7 additions & 5 deletions SimpleSockets/Client/SimpleSocketTcpSslClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ public override void StartClient(string ipServer, int port, int reconnectInSecon

if (EnableExtendedAuth)
SendAuthMessage();
else
SendBasicAuthMessage();

Endpoint = new IPEndPoint(GetIp(ipServer), port);

TokenSource = new CancellationTokenSource();
Token = TokenSource.Token;


Task.Run(SendFromQueue, Token);

Task.Run(() =>
Expand Down Expand Up @@ -339,7 +340,7 @@ protected internal override void Receive(IClientMetadata state, int offset = 0)
}
}

protected override async void ReceiveCallback(IAsyncResult result)
protected override void ReceiveCallback(IAsyncResult result)
{
var state = (ClientMetadata)result.AsyncState;
try
Expand Down Expand Up @@ -369,18 +370,19 @@ protected override async void ReceiveCallback(IAsyncResult result)
{
if (state.SimpleMessage == null)
state.SimpleMessage = new SimpleMessage(state, this, Debug);
await state.SimpleMessage.ReadBytesAndBuildMessage(receive);
state.SimpleMessage.ReadBytesAndBuildMessage(receive);
}
else if (receive > 0)
await state.SimpleMessage.ReadBytesAndBuildMessage(receive);
state.SimpleMessage.ReadBytesAndBuildMessage(receive);
}

_mreRead.Set();
_mreReceiving.Set();
}
catch (SocketException se)
{
RaiseLog("Server was forcibly closed.");
Log("Server was forcibly closed.");
Log(se);
state.Reset();
DisposeSslStream();
_mreRead.Set();
Expand Down
Loading

0 comments on commit cbdb8e4

Please sign in to comment.