Example Application
I have started the following application,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Net.DDP.Client;
namespace Net.DDP.Client.Cli
{
class Program
{
static void Main(string[] args)
{
IDataSubscriber subscriber = new Subscriber();
DDPClient client = new DDPClient(subscriber);
client.Connect("localhost:3000");
client.Subscribe("allMovies");
}
}
public class Subscriber : IDataSubscriber
{
public void DataReceived(dynamic data)
{
try
{
if (data.type == "sub")
{
Console.WriteLine(data.title + ": " + data.director);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
Everytime I start the debug, it seems that the command prompt doesn't have any output even though my publish in meteor has some data.
On the Server.js i have this file:
// Declare server Movies collection
Movies = new Meteor.Collection("movies");
// Seed the movie database with a few movies
Meteor.startup(function () {
if (Movies.find().count() == 0) {
Movies.insert({ title: "Star Wars", director: "Lucas" });
Movies.insert({ title: "Memento", director: "Nolan" });
Movies.insert({ title: "King Kong", director: "Jackson" });
}
});
Meteor.publish("allMovies", function () {
return Movies.find(); // everything
});
Any recommendations?
For anybody still looking at this, the issue is that newer versions of Meteor require a value to be sent for version in the connect message. I modified _socket_Opened() in DDPConnector to the following:
this.Send("{\"msg\":\"connect\", \"version\": \"pre1\" }");
Thanks for the tip @thebeekeeper I'm still new to Meteor, may have failed to catch this in the DDP docs.
It wasn't in the docs, I just tried a few changes in the code and it ended up working
Thanks thebeekeeper for fixing the issue. I was very busy for last so many months and unable to spend any time for this project.
Thanks @thebeekeeper! Very tricky problem indeed because it's not yet properly documented. I hope MeteorJS docs would really improve.
On Wed, Nov 6, 2013 at 1:05 PM, Sony Arouje [email protected]:
Thanks thebeekeeper for fixing the issue. I was very busy for last so many months and unable to spend any time for this project.
— Reply to this email directly or view it on GitHubhttps://github.com/sonyarouje/DDPClient.NET/issues/2#issuecomment-27843360 .
I can't receive any data in my C# program. I just followed a similar code as above. I also rebuilt the client.dll because I added @thebeekeeper's suggestion.
I can however see that someone subscribe to the collection when I ran my application (I added a console.log inside the publish).
I was able to make the call work. But I can't understand how to make subscription work. I just wanted to inform my client that a document is added in the collection. I tried to .observeChanges the collection and added a handle for the added event in the callback. For the C# program, I added an if(data.type=="added"). I tried adding a document but the client never received anything.
If the new document was added directly to MongoDB without going through an insert command from one of the collections at Meteor Layer, the subscribe should take longer to realize there are changes (about 10 sec). Try adding through Meteor Collection.Insert if this changes the case.
I've waited for more than 5 minutes. But there was no response. For the Nodejs version of the DDP client, there was no problem.
I will check this out.
I had no callback in the Subscriber::DataReceived(dynamic data) too. But I noticed that when adding an item with Products.insert() in the meteor server side, the JsonDeserializeHelper::Deserialize(string jsonItem) function was called. Then I added there an "else if (jObj["msg"] != null) { // some code; this._subscriber.DataReceived(entity); }" to call the subsriber.