Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mjaric/fenix
.NET implementation of Phoenixframework websocket socket protocol
https://github.com/mjaric/fenix
phoenix-channels phoenix-elixir phoenix-framework websocket
Last synced: 3 months ago
JSON representation
.NET implementation of Phoenixframework websocket socket protocol
- Host: GitHub
- URL: https://github.com/mjaric/fenix
- Owner: mjaric
- License: apache-2.0
- Archived: true
- Created: 2019-02-21T20:55:10.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T06:35:10.000Z (almost 3 years ago)
- Last Synced: 2024-10-05T00:20:04.001Z (4 months ago)
- Topics: phoenix-channels, phoenix-elixir, phoenix-framework, websocket
- Language: C#
- Size: 360 KB
- Stars: 30
- Watchers: 2
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-elixir-gaming - Fenix: .NET Standard 2 implementation of Phoenix framework websockets protocol
- awesome-elixir-gaming - Fenix: .NET Standard 2 implementation of Phoenix framework websockets protocol
README
# Fenix
Thread safe .NET Standard 2 implementation of Phoenix framework websocket protocol.## Supported/Tested .NET Runtime
- NETCore 2.1.0
- Mono 5.16.0.221
- .NET Framework 4.6 and above## Dependencies:
- Newtonsoft.Json 12.0.1## Usage
#### Add Dependency to Fenix NuGet Package
Add Fenix nuget dependency either using your IDEs Package Manager tool or using command line:```
$ dotnet add package Fenix
```
or amend your csproj/vbproj by adding:
``````
and then build your project for example:
```
$ dotnet build MyProject.csproj
```#### Create Fenix Socket
```c#
use Fenix;// some constants
const token = "dsa90disadojsaoijadoiajsodiajs";// Defaults should be ok, but you can tweak some options, e.g. tur on logging, max retries etc..
var settings = new Settings();
var socket = new Socket(settings);
try
{
var uri = new Uri("ws://localhost:4000/socket/websocket");
// "token" is not required, but below is demo how to pass parameteters while connecting
await _socket.ConnectAsync(uri, new[] {("token", token)});
var channel = _socket.Channel("room:lobby", new {NickName = "Timotije"});
channel.Subscribe("new_msg", (ch, payload) =>
{
Console.WriteLine($@"
Got LOBBY message
{payload.Value("body")}
");
});
var result = await channel.JoinAsync();
Console.WriteLine($"Lobby JOIN: status = '{result.Status}', response: {result.Response}");
await channel.SendAsync("new_msg", new {body = "Hi guys 2"});
Task.Delay(10000)
.ContinueWith(async task => { await channel.LeaveAsync(); })
.ConfigureAwait(false);
}
catch (Exception ex)
{
Console.WriteLine($"Error: [{ex.GetType().FullName}] \"{ex.Message}\"");
}
```