Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dajuric committed Oct 11, 2017
0 parents commit 5f625e8
Show file tree
Hide file tree
Showing 57 changed files with 3,607 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# NuGet
*.nuget.props
*.nuget.targets

**/packages/*
!**/packages/build/

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Ss]amples/**/*.js
[Dd]ebug/
[Rr]elease/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015 cache/options directory
.vs/

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/





Binary file added .nuget/NuGet.exe
Binary file not shown.
Binary file added Deploy/Logo/Logo-big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Deploy/Logo/Logo-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Deploy/Logo/WebSocketRPC.pptx
Binary file not shown.
31 changes: 31 additions & 0 deletions Deploy/Nuget/Build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
::
@echo off
:: timeout /T 5

:: settings
set nugetPath=%cd%\..\.nuget
set version=0.5.0
set output=%cd%\bin

:: Create output directory
IF NOT EXIST "%output%\" (
mkdir "%output%"
)

:: Remove old files
echo.
echo Remvoing old packages:
for /r %%f in (*.nupkg) do (
echo %%f
del "%%f"
)

echo.
echo Creating packages for:
for /r %%f in (*.nuspec) do (
echo %%f
"%nugetPath%\nuget.exe" pack "%%f" -Version %version% -OutputDirectory "%output%" -Verbosity quiet
)

echo.
pause
16 changes: 16 additions & 0 deletions Deploy/Nuget/Push.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
::
@echo off
timeout /T 5

:: settings
set nugetPath=%cd%\..\.nuget

echo.
echo Pushing packages:
for /r %%f in (*.nupkg) do (
echo %%f
"%nugetPath%\nuget.exe" push "%%f"
)

echo.
pause
13 changes: 13 additions & 0 deletions Deploy/Nuget/UpdateNuGet.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
::
@echo off
set nugetPath=%cd%\..\.nuget

:: Make sure the nuget executable is writable
attrib -R "%nugetPath%\nuget.exe"

echo.
echo Updating NuGet...
"%nugetPath%\nuget.exe" update -Self

echo.
pause
28 changes: 28 additions & 0 deletions Deploy/Nuget/nuSpecs/WebsocketRPC.JS.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>WebsocketRPC.JS</id>
<version>$version$</version>
<title>WebsocketRPC.JS</title>
<authors>Darko Jurić</authors>
<owners>Darko Jurić</owners>
<!--<iconUrl></iconUrl>-->
<description>
Generates the Javascript code for websocket-connection using the provided .NET interface.
</description>
<summary>Generates the Javascript code for websocket-connection using the provided .NET interface.</summary>
<tags>websocket; websocket-client; Javascript; RPC; C#; .NET</tags>

<dependencies>
</dependencies>

<frameworkAssemblies>
</frameworkAssemblies>
</metadata>

<files>
<file src="..\..\..\Source\WebsocketRPC.JS\bin\WebsocketRPC.JS.dll" target="lib\net47\WebsocketRPC.JS.dll" />
<file src="..\..\..\Source\WebsocketRPC.JS\bin\WebsocketRPC.JS.xml" target="lib\net47\WebsocketRPC.JS.xml" />
</files>
</package>
30 changes: 30 additions & 0 deletions Deploy/Nuget/nuSpecs/WebsocketRPC.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>WebsocketRPC</id>
<version>$version$</version>
<title>WebsocketRPC</title>
<authors>Darko Jurić</authors>
<owners>Darko Jurić</owners>
<!--<iconUrl></iconUrl>-->
<description>
Provides full duplex RPC over websocket.
</description>
<summary>Provides full duplex RPC over websocket.</summary>
<tags>websocket; RPC; C#; .NET</tags>

<dependencies>
<dependency id="Newtonsoft.Json" version="10.0.3" />
</dependencies>

<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Net.Http" />
</frameworkAssemblies>
</metadata>

<files>
<file src="..\..\..\Source\WebsocketRPC\bin\WebsocketRPC.dll" target="lib\net47\WebsocketRPC.dll" />
<file src="..\..\..\Source\WebsocketRPC\bin\WebsocketRPC.xml" target="lib\net47\WebsocketRPC.xml" />
</files>
</package>
23 changes: 23 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The MIT License (MIT)

Copyright (c) Darko Jurić

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Licensing for JSON.NET dependency also applies: https://www.newtonsoft.com/json
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<p align="center">
<a href="https://www.nuget.org/profiles/dajuric"> <img src="Deploy/Logo/logo-big.png" alt="WebSocketRPC logo" width="120" align="center"> </a>
</p>

<!--
<p align="center">
<a href="https://www.nuget.org/profiles/dajuric"> <img src="https://img.shields.io/badge/WebSokcetRPC-v1.0.1-blue.svg?style=flat-square" alt="NuGet packages version"/> </a>
<a href="https://www.nuget.org/profiles/dajuric"> <img src="https://img.shields.io/badge/WebSokcetRPC.JS-v1.0.1-blue.svg?style=flat-square" alt="NuGet packages version"/> </a>
</p>
-->

**WebSokcetRPC** - RPC over weboskcets for .NET
Leightweight .NET framework for making RPC over websockets. Supports full duplex connections; .NET or Javascript clients.

<!-- > **Tutorial:** <a href="http://www.codeproject.com/Articles/828012/Introducing-Lightweight-Weboskcet-RPC-library-for-Csharp" target="_blank">CodeProject article</a>-->


## Why WebSocketRPC ?

+ **Lightweight**
The only dependency is <a href="https://www.newtonsoft.com/json">JSON.NET</a> library used for serialization/deserialization.

+ **Simple**
There is only one relevant method: **Bind** for binding object/interface onto connection, and **CallAsync** for calling RPCs.

+ **Connection relaying in a single line of code**
The library is capable to relay incoming requests to a background services with just one command: **Relay**

+ **Automatic Javascript code generation** *(WebsocketRPC.JS package)*
Javascript websokcet client code is automatically generated (with JsDoc comments) from an existing .NET
interface (API contract).


## Sample

To scratch the surface... *(RPC in both directions, connection relaying, multi-service, .NET clients)*

**Server**
``` csharp
class MathAPI
{
public async Task<int> LongRunningTask(int a, int b)
{
await Task.Delay(250);
return a + b;
}
}

....
//generate js code
File.WriteAllText("MathAPI.js", RPCJs.GenerateCallerWithDoc<MathAPI>());
//run server
Server.ListenAsync("http://localhost:8000/", CancellationToken.None,
(c, wc) => c.Bind<MathAPI>(new MathAPI()))
.Wait(0);
```

**Client**
``` javascript
var api = new MathAPI("ws://localhost:8000");
api.connect(async () =>
{
var r = await api.longRunningTask(5, 3);
console.log("Result: " + r);
});
```


## Getting started
+ Samples
<!--+ <a href="http://www.codeproject.com/Articles/828012/Introducing-Lightweight-Weboskcet-RPC-library-for-Csharp" target="_blank">CodeProject article</a>-->

## How to Engage, Contribute and Provide Feedback
Remember: Your opinion is important and will define the future roadmap.
+ questions, comments - message on Github, or write to: darko.juric2 [at] gmail.com
+ **spread the word**

## Final word
If you like the project please **star it** in order to help to spread the word. That way you will make the framework more significant and in the same time you will motivate me to improve it, so the benefit is mutual.
45 changes: 45 additions & 0 deletions Samples/ClientJs/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using WebsocketRPC;

namespace TestClientJs
{
interface IRemoteAPI
{
bool WriteProgress(float progress);
}

class LocalAPI
{
public async Task<int> LongRunningTask(int a, int b)
{
for (var p = 0; p <= 100; p += 5)
{
await Task.Delay(250);
await RPC.For<IRemoteAPI>(this).CallAsync(x => x.WriteProgress((float)p / 100));
}

return a + b;
}
}

public class Program
{
//if access denied execute: "netsh http delete urlacl url=http://+:8001/"
static void Main(string[] args)
{
//generate js code
File.WriteAllText($"../Site/{nameof(LocalAPI)}.js", RPCJs.GenerateCallerWithDoc<LocalAPI>());

//start server and bind its local and remote API
var cts = new CancellationTokenSource();
Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) => c.Bind<LocalAPI, IRemoteAPI>(new LocalAPI())).Wait(0);

Console.Write("Running: '{0}'. Press [Enter] to exit.", nameof(TestClientJs));
Console.ReadLine();
cts.Cancel();
}
}
}
61 changes: 61 additions & 0 deletions Samples/ClientJs/ServerClientJs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C0449FA5-C667-4B5C-878A-04773903B130}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClientJs</RootNamespace>
<AssemblyName>ClientJs</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Source\WebSocketRPC.JS\WebSocketRPC.JS.csproj">
<Project>{965791bf-8f77-4a69-97e2-8b6b66cf9863}</Project>
<Name>WebSocketRPC.JS</Name>
</ProjectReference>
<ProjectReference Include="..\..\Source\WebsocketRPC\WebsocketRPC.csproj">
<Project>{AB4A5DDF-1F91-4AF8-9E9C-242832576C5E}</Project>
<Name>WebsocketRPC</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Site\Index.html" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit 5f625e8

Please sign in to comment.