DDPClient.NET icon indicating copy to clipboard operation
DDPClient.NET copied to clipboard

Example Application

Open bangonkali opened this issue 12 years ago • 11 comments

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?

bangonkali avatar Aug 07 '13 22:08 bangonkali

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\" }");

thebeekeeper avatar Nov 05 '13 17:11 thebeekeeper

Thanks for the tip @thebeekeeper I'm still new to Meteor, may have failed to catch this in the DDP docs.

bangonkali avatar Nov 05 '13 20:11 bangonkali

It wasn't in the docs, I just tried a few changes in the code and it ended up working

thebeekeeper avatar Nov 05 '13 20:11 thebeekeeper

Thanks thebeekeeper for fixing the issue. I was very busy for last so many months and unable to spend any time for this project.

sonyarouje avatar Nov 06 '13 05:11 sonyarouje

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 .

bangonkali avatar Nov 06 '13 11:11 bangonkali

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).

engkan2kit avatar Dec 21 '13 07:12 engkan2kit

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.

engkan2kit avatar Dec 21 '13 09:12 engkan2kit

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.

bangonkali avatar Dec 25 '13 18:12 bangonkali

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.

engkan2kit avatar Dec 26 '13 07:12 engkan2kit

I will check this out.

sonyarouje avatar Jan 06 '14 07:01 sonyarouje

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.

stefanopiovesan avatar Apr 19 '14 07:04 stefanopiovesan