Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpdaniels committed Aug 11, 2015
2 parents ebd20d2 + 758a4b8 commit 1f65354
Showing 1 changed file with 58 additions and 7 deletions.
65 changes: 58 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MiniWamp
========

A (relatively) small implementation of WAMP for .NET 4.5.1 and Windows 8.1.
A (relatively) small implementation of WAMP for .NET 4.5 and Windows (Phone) 8.1.

Currently only supports WAMP v1 but who knows v2 might be in the cards

Expand All @@ -25,7 +25,7 @@ using DapperWare;
Task<WampSession> session = WampClient.ConnectAsync("ws://localhost:3000");

//You can also implement your own transport as long as it implements IWampTransport
//Notice that we can await the connection to complete it asynchronously
//We can use the handy await keyword to wait for everything to start up
var session2 = await WampClient.ConnectAsync("ws://localhost:3000", new MyTransportFactory());
```

Expand All @@ -34,24 +34,75 @@ Super simple right?
But wait there's more!
Say you want to actually use Wamp to do something!

MiniWamp implements all the of the [Version 1 spec](http://wamp.ws/spec/wamp1/) (if you find something it doesn't, kindly submit a bug report).

##### Subscribing and Unsubscribing

```csharp
//Subscription
//Don't worry subscriptions will be shared if there are multiple ones
IWampSubject<string> mySubject = session.Subscribe("mytopic/something");

//Start listening for messages from the subject
mySubject.Message += mySubject_MessageHandler;

//There are two ways to unsubscribe
//Unsubscribes only this subject
mySubject.Dispose();

//Deprecated - Use .Dispose() instead
mySubject.Unsubscribe();

//Unsubscribes all subjects
session.Unsubscribe("mytopic/something");
//Unsubscribes all subjects on this topic
session.Unsubscribe("http://mytopic/something");

//Unsubscribes all subjects everywhere
session.Unsubscribe();

```

##### Publishing messages

```csharp

//Publication
session.Publish("mytopic/somethingelse", new JObject(), excludeMe: true);
session.Publish("http://mytopic/somethingelse", "Hello, world!");

//Don't receive your own publication
session.Publish("http://mytopic/somethingelse", 42, excludeMe: true);

//Add fine grained control to who can listen and who can't
session.Publish("http://mytopic/somethingelse", new MyCustomObject(),
["someid1", "someid2"], /*Exclude*/
["someid3", "someid4"] /*Eligible*/);


```

##### Calling methods
```csharp
var sum = await session.Call<int>("rpc#add", 3, 4); //sum = 7
//Exceptions in the call should be handled with try/catch
try {
var sum = await session.Call<int>("rpc#add", 3, 4); //sum = 7
} catch (WampCallException ex) {
//Handle the exception
}

```

##### Using Prefixes

```csharp

//Note: you will still use the full uri when calling methods, but under the covers
//MiniWamp will swap it out with the prefix before sending.
session.Prefixes.Add("calc", "http://mytopic/methods#");


//RPC
var sum = await session.Call<int>("rpc#add", 3, 4); //7
i.e. session.Call<int>("http://mytopic/methods#random") -> [2, callid, "calc:random"]

```

0 comments on commit 1f65354

Please sign in to comment.