Skip to content

Commit

Permalink
Added KeepAlives, PiRelay Plate Reference Updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
TWhidden committed Oct 8, 2018
1 parent 02c004d commit f2419f3
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
15 changes: 12 additions & 3 deletions HolidayShowClient.Core/Containers/ProtocolClient.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HolidayShowEndpointUniversalApp.Services;
using HolidayShowLib;
using RailwaySharp.ErrorHandling;

namespace HolidayShowEndpointUniversalApp.Containers
{
Expand Down Expand Up @@ -37,6 +34,8 @@ private void CreateClientSocket()

_client = new TcpClient();
_client.BeginConnect(_endPoint.EndPoint.Host, _endPoint.EndPoint.Port, ClientConnectionCompleted, null);
_client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
_client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1000);
}

private void ClientConnectionCompleted(IAsyncResult r)
Expand All @@ -48,9 +47,12 @@ private void ClientConnectionCompleted(IAsyncResult r)
if (!_client.Connected)
{
Disconnect();
Console.WriteLine("Connected == False!");
return;
}

Console.WriteLine($"Connected to {_endPoint.EndPoint.Host}:{_endPoint.EndPoint.Port}!");

_stream = _client.GetStream();

NetworkStreamRead();
Expand All @@ -73,6 +75,13 @@ private async void NetworkStreamRead()
_cancellationTokenSource = new CancellationTokenSource();
var bufferRead = await _stream.ReadAsync(_readBuffer, 0, BufferLength, _cancellationTokenSource.Token);

if (bufferRead == 0)
{
// 0 byte indicates a disconnected.
Console.Write("0 bytes detected on receive. Reconnect");
Disconnect();
}

var data = new byte[bufferRead];
Buffer.BlockCopy(_readBuffer, 0, data, 0, bufferRead);
BytesReceived(data);
Expand Down
6 changes: 6 additions & 0 deletions HolidayShowClient.Core/HolidayShowClient.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyVersion>2.18.1007.0</AssemblyVersion>
<FileVersion>2.18.1007.0</FileVersion>
<Version>2.18.1007.0</Version>
<Authors>Travis Whidden</Authors>
<Company>None</Company>
<Description>Client for RP3 devices</Description>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
4 changes: 2 additions & 2 deletions HolidayShowServer.Core/HolidayShowServer.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<Authors>Travis Whidden</Authors>
<Company>None</Company>
<AssemblyName>holidayshowserver.core</AssemblyName>
<AssemblyVersion>2.18.0924.0</AssemblyVersion>
<AssemblyVersion>2.18.1007.0</AssemblyVersion>
<FileVersion>2.18.0924.0</FileVersion>
<Configurations>Debug;Release;ReleaseCore</Configurations>
<Version>2.18.0924</Version>
<Version>2.18.1007</Version>
<PackageReleaseNotes>Reduced Database calls to reduce CPU. Code cleanup</PackageReleaseNotes>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion HolidayShowServer.Core/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"HolidayShowServer.Core": {
"commandName": "Project",
"commandLineArgs": "-p 5555 -d \"10.64.128.100,1401\" -n \"HolidayShow_Dev\" -u \"dev\" -s \"dev123\"",
"commandLineArgs": "-p 5556 -d \"10.64.128.100,1401\" -n \"HolidayShow_Dev\" -u \"dev\" -s \"dev123\"",
"environmentVariables": {
"DBUSER": "dev",
"DBNAME": "HolidayShow_Dev",
Expand Down
3 changes: 2 additions & 1 deletion HolidayShowServer/TcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ protected virtual void InvokeOnClientConnected(NewClientEventArgs e)
private void AcceptClient()
{
_listener.BeginAcceptTcpClient(EndAcceptClient, null);

}

private void EndAcceptClient(IAsyncResult a)
{
try
{
var client = _listener.EndAcceptTcpClient(a);
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1000);
InvokeOnClientConnected(new NewClientEventArgs(client));
}
catch
Expand Down
Binary file modified References/PiRelayPlate.NetCore.dll
Binary file not shown.
28 changes: 14 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
version: '3.4'

services:
# HolidayShowClient:
# image: holidayshowclient
# build:
# context: .
# dockerfile: HolidayShowClient.Core/Dockerfile
HolidayShowClient:
image: holidayshowclient
build:
context: .
dockerfile: HolidayShowClient.Core/Dockerfile


#HolidayShowServer:
# image: holidayshowserver
# build:
# context: .
# dockerfile: HolidayShowServer.Core/Dockerfile

HolidayShowEdit:
image: holidayshowedit
HolidayShowServer:
image: holidayshowserver
build:
context: .
dockerfile: HolidayShowWeb/Dockerfile
dockerfile: HolidayShowServer.Core/Dockerfile

#HolidayShowEdit:
# image: holidayshowedit
# build:
# context: .
# dockerfile: HolidayShowWeb/Dockerfile

0 comments on commit f2419f3

Please sign in to comment.