[solved]null-terminated stream

einsTeIn.NET
Member Posts: 1,050
Hi there,
afaik strings in NAV are containing their length in the first character. So, they are not null-terminated (like in C). I want to transfer some data to an external system. The connection type is socket and the data should be transfered as stream. The external system expects a null-termination at the end of a stream.
I did the following...
afaik strings in NAV are containing their length in the first character. So, they are not null-terminated (like in C). I want to transfer some data to an external system. The connection type is socket and the data should be transfered as stream. The external system expects a null-termination at the end of a stream.
I did the following...
IF ISCLEAR(CC2) THEN CREATE(CC2); IF ISCLEAR(SBA) THEN CREATE(SBA); CC2.AddBusAdapter(SBA, 0); OutMsg := CC2.CreateoutMessage('Sockets://localhost:5006'); OutS := OutMsg.GetStream(); OutS.WRITETEXT('Some Text 1'); OutS.WRITETEXT('Some Text 2'); OutS.WRITETEXT('Some Text 3'); OutS.WRITETEXT(); IF NOT OutMsg.Send(0) THEN ...but the external system doesn't react. So, I wonder if the stream isn't null-terminated and the external system doesn't catch the message.
"Money is likewise the greatest chance and the greatest scourge of mankind."
0
Comments
-
You could try doing...
//nullchar declared as Text (length 1~) or Char, whatever you want nullchar[1] := 0; //...YourCode... OutS.WRITETEXT('Some Text 1'); OutS.WRITETEXT('Some Text 2'); OutS.WRITETEXT('Some Text 3'); OutS.WRITETEXT(); OutS.WRITE(nullchar); //...etc...
Let me know if it works0 -
I'm not sure if I could test it like this
CU 50000 (single instance)OnRun() IF ISCLEAR(CC2) THEN CREATE(CC2); IF ISCLEAR(SBA) THEN CREATE(SBA); CC2.AddBusAdapter(SBA,0); SBA.OpenSocket(6006,'');
CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH") InMsg := InMessage; InS := InMsg.GetStream(); WHILE NOT (InS.EOS) DO BEGIN IF InS.READ(Txt) > 0 THEN FOR i := 1 TO STRLEN(Txt) DO BEGIN charint := Txt[i]; MESSAGE('%1 = %2',Txt[i],charint); END; END; InMsg.CommitMessage();
CU 50001OnRun() IF ISCLEAR(CC2) THEN CREATE(CC2); IF ISCLEAR(SBA) THEN CREATE(SBA); NullChar[1] := 0; CC2.AddBusAdapter(SBA, 0); OutMsg := CC2.CreateoutMessage('Sockets://localhost:6006'); OutS := OutMsg.GetStream(); OutS.WRITE('1st Text'); OutS.WRITE('2nd Text'); OutS.WRITE(NullChar); OutMsg.Send(0);
but if... it doesn't work. I don't know how null character would be displayed in NAV, but should I get a message off it?"Money is likewise the greatest chance and the greatest scourge of mankind."0 -
I'm not sure what you're asking...
Are you referring to the MessageReceived procedure, or in general how NAV would handle a NULL terminating string when displaying?0 -
2nd one. General handling. After some test I think NAV won't display anything. And I think NAV will interpret a zero byte as EOS.
OnRun() IF ISCLEAR(CC2) THEN CREATE(CC2); IF ISCLEAR(SBA) THEN CREATE(SBA); Text1 := '1st Text'; Text2 := '2nd Text'; Text1[4] := 0; CC2.AddBusAdapter(SBA, 0); OutMsg := CC2.CreateoutMessage('Sockets://localhost:6006'); OutS := OutMsg.GetStream(); OutS.WRITE(Text1); OutS.WRITE(Text2); OutMsg.Send(0);
If so I can be sure of that NAV creates a stream the external system is able to understand.
If not and there are other reasons why NAV doesn't display the whole stream, I have no chance to proof if the external system receives an understandable stream. In any case not with two NAV clients."Money is likewise the greatest chance and the greatest scourge of mankind."0 -
With an outstream variable you will get the null-terminated string / zero byte as EOS if you use
OutS.WRITE
If you useOutS.WRITETEXT
you won't get it."Money is likewise the greatest chance and the greatest scourge of mankind."0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions