locked
Error in distributed app? RRS feed

  • Question

  • Hi chaps,

    I am determined to crack this distributed stuff. Please have a look at my code here:

    using System;
    using Microsoft.Axum;
    using System.Concurrency.Messaging;
    using System.ServiceModel;
    
    namespace SimpleDistro
    {
      channel Simple
      {
        input string InputMessage;
        output string OutputMessage;
      }
      
      domain ServiceDomain 
      { 
        public agent ServiceAgent : channel Simple
        { 
          public ServiceAgent () 
          { 
            // Do something useful.
            string message = receive(PrimaryChannel::InputMessage);
            PrimaryChannel::OutputMessage <-- message;
          } 
        } 
      }
      
      public domain Program
      {
        agent Server : channel Microsoft.Axum.Application
        {
          public Server()
          {
            String [] args = receive(PrimaryChannel::CommandLine);
            
            var auctionAddr = "net.tcp://localhost:4711/simpleService1";
            
            bool isServer = (args.Length > 0 && args[0] == "server");
            
            if(isServer)
    		{
    		  var hst = new TcpServiceHost();
              //var hst = new WcfServiceHost(new NetTcpBinding(SecurityMode.None, false));
              hst.Host<ServiceDomain.ServiceAgent>(auctionAddr, new ServiceDomain());
            }
    
            var prov = new TcpCommunicationProvider();
    		//var prov = new WcfCommunicationProvider(new NetTcpBinding(SecurityMode.None, false));
    		var chan = prov.Connect<Simple>(auctionAddr);
                             
            if(isServer)
            {
              Console.WriteLine("Server started.");
              
              while(true)
              {
    			var msg = receive(chan::OutputMessage); // <------- NEVER RECEIVING!
                Console.WriteLine(msg);          
              }
    		}
            else
            {
              Console.WriteLine("Client started.");
              while(true)
              {
    			string msg = Console.ReadLine();
                chan::InputMessage <-- msg;
              }
            }
    
            PrimaryChannel::Done <-- Signal.Value;
          }
        }
      }
    }
    

    http://pastebin.com/J8EX2MWU

     

    The error is that line 56:

    var msg = receive( chan:: OutputMessage )

    is never getting through. So I can only assume my channels are pointing to different places? But why? I can't figure it out. If I debug the server and run a client then the ServiceAgent is getting constructed so the OutputMessage is having a string passed to it but the main server agent just...doesn't repond to the receive.


    I'm sure it's something tiny...

     

    Thanks!

    Wednesday, September 1, 2010 8:13 AM

Answers

  • Hi Niklas,

    Its stupid when I look at it now. My understanding of the channel/domain/agent relationship was flawed. I was expecting the server to receive messages posted on the channels belonging the clients when in fact this will never happen. The serrver creates its own, private channel and thats what it was listening for messages on and subsequently why it was never recieving any, because I was only posting messages to the client channels. I came to understand that the server owns the domain and therefore doesnt need a channel in order to communicate with clients. Sorry, this might sound complicated but I will explain it all in my tutorial.

    Friday, September 3, 2010 5:44 PM

All replies

  • I found the error. It seems it's my understanding that's the problem, not the code. I am in the process of tutorialising my code so will post the solution soon.
    Thursday, September 2, 2010 8:40 AM
  • Please do! I'm staring at your code and I'm not catching it right away, either. I'll have to debug it, I think, it irritates me that I don't see it :-)

    Niklas

    Friday, September 3, 2010 1:33 AM
    Moderator
  • Hi Niklas,

    Its stupid when I look at it now. My understanding of the channel/domain/agent relationship was flawed. I was expecting the server to receive messages posted on the channels belonging the clients when in fact this will never happen. The serrver creates its own, private channel and thats what it was listening for messages on and subsequently why it was never recieving any, because I was only posting messages to the client channels. I came to understand that the server owns the domain and therefore doesnt need a channel in order to communicate with clients. Sorry, this might sound complicated but I will explain it all in my tutorial.

    Friday, September 3, 2010 5:44 PM