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::MessageReceived@1(VAR InMessage:Automation:'.IDISPATCH"); //Displays a Message if something happens MESSAGE('Message Received!');
Comments
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
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:
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
Or Am I able to tell NAV automation which local port should id open for sending message ?
Thank you