Programming with the "Navision Socket Bus Adapter"

Henry@columbus[email protected] Posts: 24Member
edited 2004-04-16 in Navision Attain
Hello,

I’m trying to create a winsock client application with the "Navision Socket Bus Adapter". I’m having trouble with the “MessageReceived” trigger in my client. There’s no way to get the client to receive a message.

Here’s my code:
OnRun

//Check if ComCOm is clear
  IF ISCLEAR(ComCom) THEN
    IF NOT CREATE(ComCom) THEN
      ERROR('Failed to create Communication Component');
//Check if Socket Bus Adapter is clear
  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);

OutMsg:= ComCom.CreateoutMessage('Sockets://localhost:5678');
OutStr:= OutMsg.GetStream();
OutStr.WRITE('First Text');
OutMsg.Send(0);
The onevent trigger from the Comunication Component
ComCom::[email protected](VAR InMessage:Automation:'.IDISPATCH");

//Displays a Message if something happens
  MESSAGE('Message Received!');

Can anybody please help me ? :roll:

Thanks

Comments

  • Stefan_HillmannStefan_Hillmann Posts: 9Member
    Hello Henry,

    your example is quite right, but I`m missing
    one small line of code...

    SBA.OpenSocket(<your port>,'');

    you have to insert this line before adding your busadapter to the comcom object.

    <your port> means the port you want the communication component to listen at.


    good luck...


    stefan
  • Henry@columbus[email protected] Posts: 24Member
    Hello,

    Thanks for your answer.
    I did exactly what you suggested, but it’s still not working.

    I’m getting the following message: The call to member Opensocket failed. SocketBusAdapter. SocketBusAdapeter.1 returned the following message:
    Cannot open socket.

    This is because I’m already running a socket server. My goal is to communicate with this server.

    This is my code:
    //Check if ComCOm is clear
      IF ISCLEAR(ComCom) THEN
        IF NOT CREATE(ComCom) THEN
          ERROR('Failed to create Communication Component');
    //Check if Socket Bus Adapter is clear
      IF ISCLEAR(SBA) THEN
        IF NOT CREATE(SBA) THEN
          ERROR('Failed to create SBA');
    
      SBA.OpenSocket(5678,'');
    
    // Add the SBA to the Comunication Component
      ComCom.AddBusAdapter(SBA, 0);
    
      OutMsg:= ComCom.CreateoutMessage('Sockets://localhost:5678');
      OutStr:= OutMsg.GetStream();
      OutStr.WRITE('First Text');
      OutMsg.Send(0);
    
    Henry
  • chrmuellerchrmueller Posts: 9Member
    Hello Henry,

    Stefan is right. You have written code to send data over the socket (first part) -> CLIENT and you have written code to receive data (second part) -> SERVER. But I'm also missing the Opening of the socket.

    CREATE(ComCom);
    CREATE(Socket);
    ComCom.AddAdapter(Socket, 0);
    Socket.OpenSocket(12000, ''); // Opening Port 12000

    This code has to be in the "on run"-Trigger of the SERVER side. (second part).

    But the application server installation has a small but usefull (unfortunatly hidden) online help: c:\program files\shared files\navision\communication component\devguide.chm.
    Here you'll find two very easy examples (sending and receiving) for each kind of adapter. I'll think this will help.

    Regards
    Christian
  • arcrexarcrex Posts: 3Member
    Hi , is it possible to use "MessageReceived" event for communicating with "BlackBox" which sends answer to dynamically changing port opened when sending messages to that remote machine ?

    Or Am I able to tell NAV automation which local port should id open for sending message ?

    Thank you
Sign In or Register to comment.