Giter VIP home page Giter VIP logo

wampsharp's Introduction

WampSharp

NuGet Version

A C# implementation of WAMP (The Web Application Messaging Protocol)

The implementation supports WAMPv2 and includes both Json and MsgPack support, and both Router (Broker and Dealer roles) and Client (Publisher/Subscriber and Callee/Caller) roles. See here for a list of implemented advanced profile features.

The implementation also supports WAMPv1, both client and server roles.

Donations

If you found WampSharp helpful and want to donate, you are welcome to do so via PayPal.

Your donations help keep this project's development alive.

Documentation

Documentation is available at https://wampsharp.net!

WampSharp v20.1.1

WampSharp v20.1.1 is available, see version release notes.

Get Started

See Get started tutorial and

See the documentation for more help.

WAMPv1 support

WAMPv1 support is still available. You can read about it on the documentation site.

In order to use it, Install WampSharp.WAMP1.Default from NuGet.

If you're updating from a previous WampSharp version and you're not interested yet in updating your application to WAMPv2, please read the following notes.

Poloniex Api issues

Poloniex no longer uses WAMP for its WebSockets api. Please don't open issues specific to Poloniex api. These will be closed without any comment. If you are still interested in connecting to Poloniex WebSockets api, take a look at PoloniexWebSocketsApi.

wampsharp's People

Contributors

alexandru-calinoiu avatar amityo avatar bigbearzhu avatar darkl avatar ghost93 avatar jerousseau avatar joreg avatar kasravi avatar konstantinryazantsev avatar mbett7 avatar samangh avatar selfcoder avatar shannonkaspernoesis avatar stevenbonepgh avatar yohskdista avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wampsharp's Issues

Serialize entire array

An optimization that serializes the entire array instead of serializing all the array elements and then the array.

Being developed on serialization-improvement branch. (Has a lot of breaking core interfaces changes)

Batched transports

See advanced profile spec.

Being developed on "batched" branch.
TODO:

  • Add suitable overloads for DefaultWampChannelFactory
  • Add binary support
  • Add a BatchedWebSocketTransport which wraps a given WebSocketTransport.

SignalR javascript transport

A transport for AutobahnJS For the SignalR transport. A draft is available here based on WebSocket transport.

Things to do:

  • Finish writing the javascript part (support specifying options)
  • Create a NuGet package for this (a AutobahnJS NuGet package will be needed to be created as well, contact Tobias)

MsgPack over RawTcp

The following code snippet:

WampHost host = new WampHost();
host.RegisterTransport(
  new RawTcp.RawTcpTransport(8080),
  new Binding.JTokenMsgpackBinding()
);

... fails in RawTcpTransport::GetListener() due to a cast to IWampTextBinding.

As far as I can see WampSharp.RawTcp does not support MsgPack, is that correct or am I missing something in setting up the WampHost?

Thanks for your help

Optimizing reflection

Using compiled delegates instead of MethodInfo.Invoke (mainly in reflection based callee and reflection based subscriber).

This is been developed in the expression-invoke branch.

override IWampRpcServer's Call method..

regarding
"I prefer the CallInvoked handler out of WampSharp.
If you can't implement this externally (by raising an event from your class), I prefer a solution which allows you to specify the IWampServer<> a (Default)WampHost<> will run against (via an interface that supplies the IWampServer, passed to the (Default)WampHost<> constructor).
This will allow you externally to override IWampRpcServer's Call method and raise a handler from there."
you mentioned in #15 can you elaborate on if this is already possible or it would still need some preparations?

Unhandled exception when calling channel.Open() with no network connection

I do like your Wamp client and it works great. However, I do see an issue when a machine comes back out of hibernation or simply loses network connectivity.

After losing the connection and when trying to reconnect to the Wamp service while the computer is not connected to the network, a thread in WampSharp throws an exception. Since the exception is thrown on a different thread, I cannot catch it and the process terminates. I have implemented the UnhandledExceptionHandler and I am able to retrieve the callstack (see below).
I believe this is due to that the connect is done asynchronously in a separate thread. Catching the exception in that thread should handle this properly.
It is easy to simulate the issue by disabling the network adapter and then trying to call channel.Open().
I would be more than happy to contribute to this project if you want me to propose a solution for this issue.

This is the callstack of the exception:
System.Net.Sockets.SocketException (0x80004005): The requested name is valid, but no data of the requested type was found
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
at System.Reactive.ExceptionHelpers.Throw(Exception exception)
at System.Reactive.Stubs.<.cctor>b__1(Exception ex)
at System.Reactive.AnonymousObserver1.OnErrorCore(Exception error) at System.Reactive.ObserverBase1.OnError(Exception error)
at System.Reactive.Observer1.OnError(Exception error) at System.Reactive.Subjects.Subject1.OnError(Exception error)
at WampSharp.WebSocket4Net.WebSocket4NetConnection`1.WebSocketOnError(Object sender, ErrorEventArgs errorEventArgs)
at WebSocket4Net.WebSocket.OnError(ErrorEventArgs e)
at WebSocket4Net.WebSocket.client_Error(Object sender, ErrorEventArgs e)
at SuperSocket.ClientEngine.ClientSession.OnError(Exception e)
at SuperSocket.ClientEngine.TcpClientSession.ProcessConnect(Socket socket, Object state, SocketAsyncEventArgs e)
at SuperSocket.ClientEngine.ConnectAsyncExtension.SocketAsyncEventCompleted(Object sender, SocketAsyncEventArgs e)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(Exception exception, Int32 bytesTransferred, SocketFlags flags)
at System.Net.Sockets.MultipleConnectAsync.Fail(Boolean sync, Exception e)
at System.Net.Sockets.MultipleConnectAsync.DoDnsCallback(IAsyncResult result, Boolean sync)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.Dns.ResolveCallback(Object context)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

state of wamp v2 implementation

helo darkl,

can you comment on the state of the wamp v2 branch? the readme.md does not mention anything. is it already supposed to be useable?

Authentication HELLO message

It seems wampv2-authentication-merge lacks some features of AutobahnJS:

See this sample:
https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/authentication/ticket/index.html

See these lines:
https://github.com/tavendo/AutobahnJS/blob/master/package/lib/session.js#L1020

This should be supported by WampSharp:

In order to do it we need to add to IWampClientAuthenticator two properties: AuthenticationMethods (string[]) and AuthenticationId (string).

We need to call these properties in WampSessionClient's OnConnectionOpen method and forward them to server's Hello message details dictionary if they aren't null (named authmethods and authid).

DefaultWampClientAuthenticator should return null for these properties.

Also, the authentication sample should be modified to be similar to the ticket sample.

Connection monitoring

The proxies provided by IClientBuilder, IServerProxyBuilder should implement an interface having events notifying when connection established and when connection lost.

WAMPv2 authorization

I asked about authorization in this question. So, I try just hardcode auth data returning and connected to my server successfully! I'm going to add onChallenge event to IWampClientConnectionMonitor. Is it good idea? Or may be other realization be better?

RPC client async support

There should be an option to call server rpc methods asynchronously.

The support should be treated in RpcClientHandler and RpcClientInterceptor: If a method returns Task or Task, just call "CallAsync" instead of "Call".

JSON Serializing

Hi,
Are you able to please provide the JSON object for getting the example https://github.com/Code-Sharp/WampSharp/wiki/Subscriber-role running ?
I keep getting KeyNotFoundException error on the line:

    string c = x.ArgumentsKeywords["c"].Deserialize<string>();

I think it can't find the "c" in the dictionary.

What I'm trying to achieve is to deserialize simple JSON into the following C# class after a web client publishes an event:

    // c# payload datA from JSON web peer
    public class PlayerMovePayload
    {
        [JsonProperty("PlayerName")]
        public string Name {get;set;}
        [JsonProperty("Direction")]
        public string Direction {get;set;}    // "Up" | "Down" | "Left" | "Right"
    }

Also, can you explain in a little more detail how the serialization works at the line:

    DPropertyClass d = x.ArgumentsKeywords["d"].Deserialize<DPropertyClass>();  // (How/what is key "d" ?!?)

Thanks...
Brad.

RawSocket client connection

Implement a RawSocket connection for clients, i.e. implement a IControlledWampConnection which connects to a router.

Think about how to reuse code from router side.

How to return an error

Hi,

I'm experimenting with WampSharp which looks great, but I'm not sure how to return an error message as described by the protocol:

http://wamp.ws/spec/#callerror_message

I can see a specific error could be thrown via creating an WampRpcCallException but this I cannot see how to pass a return argument of a method that was decorated with a
[WampRpcMethod] attribute in order to receive the proper error through the socket.

(I'm trying to Interface with autobahn javascript library)

Thanks,

Alex

Callee api

Implement the RegisterCallee method in IWampRealmServiceProvider implementations.

Publisher role

Implement client's Publisher role.
(Note: The problem here is that the publisher methods may return a publication id, and may not return anything, depending on "publishAck" value)

Client disconnection

When client disconnects router, all client pending requests should be set to an error.

FormatException when running WampV1 server samples

Hey,

When trying to run sample server from WampV1 sample servers this exception occurs:

System.FormatException occurred
  HResult=-2146233033
  Message=Failed to parse the IP address part of the location. Please make sure you specify a valid IP address. Use 0.0.0.0 to listen on all interfaces.
  Source=Fleck
  StackTrace:
       at Fleck.WebSocketServer.ParseIPAddress(Uri uri)
       at Fleck.WebSocketServer..ctor(Int32 port, String location)
       at Fleck.WebSocketServer..ctor(String location)
       at WampSharp.Fleck.FleckWampConnectionListener`1.StartServer() in e:\backup\dev\git\WampSharp\src\net45\WampSharp.Default\Fleck\FleckWampConnectionListener.cs:line 59
  InnerException: System.FormatException
       HResult=-2146233033
       Message=An invalid IP address was specified.
       Source=System
       StackTrace:
            at System.Net.IPAddress.InternalParse(String ipString, Boolean tryParse)
            at System.Net.IPAddress.Parse(String ipString)
            at Fleck.WebSocketServer.ParseIPAddress(Uri uri)
       InnerException: 

image

This happens when you use

 using (IWampHost host = new DefaultWampHost("ws://localhost:9000/"))

on tests.

If you change localhost to 127.0.0.1 it works just fine.

Looking at Fleck's source code for WebSocketServer this happens because of its' ParseIPAddress function and .net's IPAddress since it doesn't recognize localhost as valid IPAddress.

Little test:

Console.WriteLine("localhost");
Uri uri = new Uri("ws://localhost:12345");
IPAddress address;
Console.WriteLine(IPAddress.TryParse(uri.Host,out address));
Console.WriteLine("127.0.0.1");
uri=new Uri("ws://127.0.0.1:12345");
Console.WriteLine(IPAddress.TryParse(uri.Host, out address));

Output:

localhost
False
127.0.0.1
True

I will submit a PR later :)

WampSharp + SignalR = infinite loop until StackOverflow

There is no documentation for using WampSharp + SignalR, so trying to implement the documented host code, it gives me a StackOverflow on host.Open();

Which is the correct way to use SignalR + WampSharp (it is important to use OWIN, since I'm using ASP.net helios instead of system.web)

Api

The current api of wampv2 needs some work, make it more user-friendly.

Possible to set http headers for connection establishment?

Hi,

Rusty dev here and a complete n00b when it comes to WAMP...is it possible to set http headers in WampSharp to be used when establishing the connection? I have a server to connect to which requires a particular header to be sent.

Thanks in advance!

Logging

There should be logs in the framework.

A logging framework (such as log4net) should be considered.

Expression MethodBuilder

A method builder instead of the existing WampMethodBuilder which builds methods using expression trees, for faster calls.

handle reconnections

Hi,
I would like to ask you what is the proper way to reopen connection when a connection has been lost.

i try something like:

RealmProxy.Monitor.ConnectionBroken += OnError

private void OnError(object sender, EventArgs e){
Task con = _channel.Open();
t.Wait();
}

Use with Autobahn

Hello. When I try to connect WampSharp with my Python Autobahn WampServer, I get a handshake error "this server only speaks wamp.2.json". Once Wamp v2 is supported, will this be solved? Is there an alpha client that's available now?

Tests

Add tests for new WAMP2 code.

Maybe these tests should be ported (though they will be integration tests)

WampSharp publishing to Javascript kwargs

Hi,

I'm wanting to publish a topic from WampSharp to Javascript.
The javascript (autobahn.js) event is described thus:

function onPlayerMove( args, kwargs, details ) { }

I can send data to 'args' and access my payload like args[0].DataField1, args[0].DataField2, etc
but writing args[0] is a bit ugly.

I'm wanting to code my Javascript like: kwargs.payload.DataField1, kwargs.payload.DataField2, etc. I have got this code working sending/receiving topics to/from Javascript (autobahn.js), and I'm wanting to keep this same style of coding to access my payload from my C# peer.

Is there a way in WampSharp to publish to the 'kwargs' parameter ? I wasn't able to see any documnetation on this - can you assist?

Also as a note, might there not be some JSON serialisation involved as well ?

UPDATE: I can receive events in Wampsharp from the kwargs in javascript (autobahn.js). I just don't know how WampSharp can 'publish' data to kwargs.

Cheers,
Brad.

System.InvalidOperationException

System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed. Using TrySetException instead of SetException fixes the issue for me.

SUBSCRIBE fixes

See here

  • In router side: If the same client subscribes a couple of times, return the same subscription id.
  • In client side: Hold a dictionary of subscriptionId to a list of subscribers instead to a single subscriber.

User friendly

There should be an easy way to start using WampSharp, without plugging components one inside another.

The proposed idea is to have two main entry points:

-WampChannel - provides IWampServer proxies or IWampRpcClientFactory, the only parameter it gets in the constructor is the address of the server to connect to. (Note that a IWampServer proxy is tied to a IWampClient, so the user should pass an IWampClient to the method that provides the IWampServer proxy)
-WampServiceHost - provides a WampListener that routes messages to a given custom WampServer or to a predefined WampServer that routes RPC calls to user methods and etc.

Dependency injection (Ninject) looks suitable here, but should be checked.

Invoke vs. InvokeAsync

helo darkl,

thanks a lot for your work on the wamp implementation. works great here. before i come back to the topic i just wanted to quickly comment on the 2 PRs i just sent:

#16
in our application we need the possibility to dynamically register/unregister RPCs

#15
here we needed a way to be notified when a session connects/disconnects and also when an RPC call finished.

hope they work for you. let me know if you need things adapted.

back to the topic:
have you thought of a way to decide globally or per RPC whether it is invoked synchronously or asynchronously? for now it seems you default to async which doesn't work in our scenario. so for now in WampRPCServer.cs l55 we just call Invoke() instead of InvokeAsync() but of course that is not solution. any ideas?

Nuget dependencies

Why is WampSharp requiring both Websockets and Fleck?
Aren't those separate implementations for websockets?

Thank you.

Broken connection cause application crush

Application crushed when connection physically broken or wrong port will be provided for an channel connection. Catch state below is never entered. Finally block is never entered too:

channelFactory = new DefaultWampChannelFactory();
IWampClientAutenticator authenticator = new ClientAuthenticator(username, password);
channel = channelFactory.CreateJsonChannel( url, realm, authenticator );

try
{
          Task task = channel.Open();
          task.Wait();
}
catch ( Exception e )
{
        // The code below is never has been called. Application will be crushed.
        Console.WriteLine( e.Message );
}
finally
{
         // The code below is also has not being called
            Console.WriteLine( "Connection error!" );
}

RPC server-side support

The user should be able to write a "ServiceContract class" having methods the can be called remotely.

These methods are called through a WampServer Call method, and eventually call client's CallResult or CallError methods.

There should also be support for async methods that return Tasks.

A thought should be given for how to allow rpc methods call other client features, such as SessionId/Event.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.