Skip to content

Commit 170bd54

Browse files
gedemgedem
authored andcommitted
Console websocket proxy
1 parent eb40282 commit 170bd54

File tree

8 files changed

+160
-0
lines changed

8 files changed

+160
-0
lines changed

NetCoreStack.WebSockets.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WebClientTestApp2", "test\W
2828
EndProject
2929
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Common.Libs", "test\Common.Libs\Common.Libs.xproj", "{7ACFEED0-C1D7-43DE-95D7-3D2CEFDF6F9F}"
3030
EndProject
31+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ConsoleAppProxyClient", "test\ConsoleAppProxyClient\ConsoleAppProxyClient.xproj", "{1AAECD28-5C1D-4ED6-8CBC-6FCAA3804ABF}"
32+
EndProject
3133
Global
3234
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3335
Debug|Any CPU = Debug|Any CPU
@@ -62,6 +64,10 @@ Global
6264
{7ACFEED0-C1D7-43DE-95D7-3D2CEFDF6F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
6365
{7ACFEED0-C1D7-43DE-95D7-3D2CEFDF6F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
6466
{7ACFEED0-C1D7-43DE-95D7-3D2CEFDF6F9F}.Release|Any CPU.Build.0 = Release|Any CPU
67+
{1AAECD28-5C1D-4ED6-8CBC-6FCAA3804ABF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
68+
{1AAECD28-5C1D-4ED6-8CBC-6FCAA3804ABF}.Debug|Any CPU.Build.0 = Debug|Any CPU
69+
{1AAECD28-5C1D-4ED6-8CBC-6FCAA3804ABF}.Release|Any CPU.ActiveCfg = Release|Any CPU
70+
{1AAECD28-5C1D-4ED6-8CBC-6FCAA3804ABF}.Release|Any CPU.Build.0 = Release|Any CPU
6571
EndGlobalSection
6672
GlobalSection(SolutionProperties) = preSolution
6773
HideSolutionNode = FALSE
@@ -74,5 +80,6 @@ Global
7480
{7E772C91-3D01-4886-A591-BD663D9B017F} = {52C54080-F48B-4DBA-A418-8057611CAF6D}
7581
{7B3B956E-DF5A-4AD8-BCB9-14235D53471C} = {A1704016-03C8-4917-9C50-AE9DDF55ECB7}
7682
{7ACFEED0-C1D7-43DE-95D7-3D2CEFDF6F9F} = {A1704016-03C8-4917-9C50-AE9DDF55ECB7}
83+
{1AAECD28-5C1D-4ED6-8CBC-6FCAA3804ABF} = {A1704016-03C8-4917-9C50-AE9DDF55ECB7}
7784
EndGlobalSection
7885
EndGlobal

src/NetCoreStack.WebSockets.ProxyClient/ClientWebSocketConnector.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public WebSocketState WebSocketState
3030
{
3131
get
3232
{
33+
if (_webSocket == null)
34+
throw new InvalidOperationException("Make sure async instantiation completed and try again Connect!");
35+
3336
return _webSocket.State;
3437
}
3538
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.Threading.Tasks;
4+
5+
namespace NetCoreStack.WebSockets.ProxyClient
6+
{
7+
public class TaskManager
8+
{
9+
private readonly IWebSocketConnector _connector;
10+
private readonly ConcurrentQueue<Task> _operations;
11+
12+
public TaskManager(IWebSocketConnector connector)
13+
{
14+
_connector = connector;
15+
_operations = new ConcurrentQueue<Task>();
16+
_operations.Enqueue(_connector.ConnectAsync());
17+
}
18+
19+
public void Start()
20+
{
21+
22+
}
23+
}
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>1aaecd28-5c1d-4ed6-8cbc-6fcaa3804abf</ProjectGuid>
11+
<RootNamespace>ConsoleAppProxyClient</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using NetCoreStack.WebSockets;
2+
using NetCoreStack.WebSockets.ProxyClient;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.Threading.Tasks;
6+
7+
namespace ConsoleAppProxyClient
8+
{
9+
public class DataStreamingInvocator : IClientWebSocketCommandInvocator
10+
{
11+
public async Task InvokeAsync(WebSocketMessageContext context)
12+
{
13+
var values = await Task.Run(() => JsonConvert.SerializeObject(context));
14+
Console.WriteLine(values);
15+
}
16+
}
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using NetCoreStack.WebSockets;
3+
using NetCoreStack.WebSockets.ProxyClient;
4+
using NetCoreStack.WebSockets.ProxyClient.Console;
5+
using System;
6+
using System.Diagnostics;
7+
using System.Net.WebSockets;
8+
using System.Threading.Tasks;
9+
10+
namespace ConsoleAppProxyClient
11+
{
12+
public static class ApplicationVariables
13+
{
14+
public static int TaskCount = 0;
15+
public static int SocketReady = 0;
16+
}
17+
18+
public class Program
19+
{
20+
private static IServiceProvider _resolver = null;
21+
22+
public static void Main(string[] args)
23+
{
24+
var services = new ServiceCollection();
25+
services.AddProxyWebSockets(options =>
26+
{
27+
options.ConnectorName = $"ConsoleApp-{Environment.MachineName}";
28+
options.WebSocketHostAddress = "localhost:7803";
29+
options.RegisterInvocator<DataStreamingInvocator>(WebSocketCommands.All);
30+
});
31+
32+
_resolver = services.BuildServiceProvider();
33+
34+
_resolver.UseProxyWebSocket();
35+
36+
Console.ReadLine();
37+
}
38+
}
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("ConsoleAppProxyClient")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("1aaecd28-5c1d-4ed6-8cbc-6fcaa3804abf")]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": "1.0.0-*",
3+
"buildOptions": {
4+
"emitEntryPoint": true
5+
},
6+
7+
"dependencies": {
8+
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
9+
"System.Text.Encoding.CodePages": "4.3.0",
10+
"System.Runtime.InteropServices": "4.3.0",
11+
"NETStandard.Library": "1.6.1",
12+
"NetCoreStack.WebSockets": "1.0.0-*",
13+
"NetCoreStack.WebSockets.ProxyClient": "1.0.0-*"
14+
},
15+
16+
"frameworks": {
17+
"netcoreapp1.1": {
18+
"imports": [
19+
"dotnet5.6",
20+
"portable-net45+win8"
21+
],
22+
"dependencies": {
23+
"Microsoft.NETCore.App": {
24+
"type": "platform",
25+
"version": "1.1.0"
26+
}
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)