Problems withSocket Communication

urknallurknall Member Posts: 4
edited 2005-06-24 in Navision Attain
Hello,

I have a Problem with Navision Communication Component version 2.0 and Navision Socket Bus Adapter. (Sorry for my bad english :roll: )

Why isn't start my InMessage Event? see my code of a little Socket Client Application. An external Socket Server is sending data to him. My outsending Data are OK.
OnRun()
IF ISCLEAR(ComCom) THEN
    CREATE(ComCom);
  IF ISCLEAR(SBA) THEN
    CREATE(SBA);
  
  ComCom.AddBusAdapter(SBA, 0);
  
  IF ISCLEAR(OutMsg) THEN BEGIN
    OutMsg:= ComCom.CreateoutMessage('Sockets://locelhost:8888');
    OutS:= OutMsg.GetStream();
    OutS.WRITE('Hello World!'); //Test Kommuikation
    OutMsg.Send(0);
  END 
  ELSE BEGIN
    OutS:= OutMsg.GetStream();
    OutS.WRITE('Hello World!!!'); //Test Kommuikation
    OutMsg.Send(0);
  END;

ComCom::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
InMsg:= InMessage;
InS:= InMsg.GetStream();

WHILE NOT (InS.EOS) DO
  BEGIN
    InS.READ(TXT);
    MESSAGE(TXT);
END;

Thanks for your help!!!

Urknall

Comments

  • Henry@columbusHenry@columbus Member Posts: 24
    Hello Urknall,

    I’ve had the same problem. As far as I know, it’s not possible to use the event "messageReceived" on a client.
    I’ve solved the problem with the onTimer property in a from. This onTimer event triggers a function in a single instant codeunit with checks if something’s is available on the winsock buffer. I’m not using the comcom adapter but I’m using the winsock.ocx. It’s not very elegant but It works.

    Good luck

    Henry
  • urknallurknall Member Posts: 4
    Hello, Henry!

    Thanks for your fast answer :D but you have bad news!!! The solution that you propose me, i have implement a year ago.
    This solution was very inefficient!!! It is a performence-Killer!

    An other alternative is develop a Server Socket with navision, but i have the same problems. I don't understand this!

    Regards

    Urknall
  • Henry@columbusHenry@columbus Member Posts: 24
    Hello Urknall,

    Yes, it’s true it is not the best performance solution. But the a Navision socket server sould be no problem.

    As you have installed a Navision client there is a small but very usefull (hidden) OnlineHelp. You'll find it under c:\program files\shared files\navision\communication component\devguide.chm.
    This OnlineHelp gives examples (sending and receiving data) for all kinds of adapters (socket, message queue and named pipe). I think there you'll find all you need.

    Hope I could help.
  • urknallurknall Member Posts: 4
    I know this file! But there is non example for Data receiving and sending in one process!
    I have build an Server Socket application, but i received only one message in my event trigger.
    OnRun()
    IF ISCLEAR(ComCom) THEN BEGIN
        CREATE(ComCom);
      IF ISCLEAR(SBA) THEN
        CREATE(SBA);
      
      ComCom.AddBusAdapter(SBA, 0);
      SBA.OpenSocket(8888,'');
    
    
    END ELSE
      begin;
        CLEAR(ComCom);
        CLEAR(SBA);
      END;
    
    ComCom::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
    
    IInMsg:= InMessage;
    InS:= IInMsg.GetStream();
    
    WHILE NOT (InS.EOS) DO
      BEGIN
        InS.READ(TXT);
        MESSAGE(TXT);
      END;
      
      IF IInMsg.ExpectReply THEN BEGIN
        //MESSAGE('Antwort erforderlich!!!');
    
        IOutMsg := IInMsg.CreateReply;
        OutS:= IOutMsg.GetStream();
        IOutMsg.Send(0);
      
      END;
      
      //IInMsg.CommitMessage();
    

    When i set the CommitMessage Command the Connection will be killed!
    And how can i send my data to connected clients? How can i identify connected clients? thats all my problems :)

    Kind Regards

    Urknall
  • Henry@columbusHenry@columbus Member Posts: 24
    Hello Urknall,

    Here is a example for Data receiving and sending in one process. It’s is possible to identify connected clients by there IP address using The Source Property. This property reveals the IP address of the sender of the message.
    OnRun()
    IF ISCLEAR(ComCom) THEN
      IF NOT CREATE(ComCom) THEN
        ERROR('Failed to create Communication Component');
    IF ISCLEAR(SBA) THEN
      IF NOT CREATE(SBA) THEN
        ERROR('Failed to create SBA');
    
    // Add the SBA to the Comunication Component
      ComCom.AddBusAdapter(SBA, 0);
    
    //Open the Socket on Port 5678, the name of the Socket is socketname
    SBA.OpenSocket(5678, 'socketname');
    SBA.ReceivingTimeout := 20000;
    
    ComCom::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
    InMsg := InMessage;
    InStr := InMsg.GetStream();
    
    //Create a string 
    InStr.READTEXT(str);
    IF str <> '' THEN
      MESSAGEstr := 'Hello ' + str + InMsg.Source;
    
    //Create Reply
    OutMsg:= InMsg.CreateReply;
    
    //Write something into the OutStream
    OutStr:= OutMsg.GetStream();
    
    //Copy Incoming Msg into Outgoing Msg
    OutStr.WRITETEXT(MESSAGEstr);
    
    //Send Reply Msg - the 0 means send it right away.
    OutMsg.Send(0);
    InMsg.CommitMessage();
    
    The Navision Socket Bus adapter is a very strange component. :roll: For example it can have multiple connections, but I can only process one connection a time. And yes it kills the connection when the CommitMessage is send. There’s nothing you can do about it. Navision 4.0 will be more .NET based so perhaps there will be a better socket bus adapter in Navision 4.0.

    Good luck,

    Henry
  • BGIBGI Member Posts: 176
    You also have the counterpart of this code, the code that sends the message and receives the answer in navision?
    Rgds
    Benny
    Rgds
    Benny Giebens
  • DenSterDenSter Member Posts: 8,307
    Continuous socket server in Navision = not possible.

    Navision 4.0 = no improvement.

    You'll have to write your own external socket server component and send it into something Navision understands, like a message queue.
Sign In or Register to comment.