Recieve response from TCP - function call amiguous

PJE99
Member Posts: 2
Hi,
I am having problems recieving response from TCP-server through dotnet-vars.
I am connecting to a TCP-server. Then I am sending a command to the TCP-server. When the TCP-server recieves the command it sends simple info back (just to make sure that the command from NAV has been recieved by the TCP-server).
I am able to send the command, but when I add code to recieve the response, I get compile error "Function call is ambiguous. No matching method found". Am I doing it wrong? Or is this not possible?
My code and vars goes here:
TCPDotNet DotNet System.Net.Sockets.TcpClient.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
NetStream DotNet System.Net.Sockets.NetworkStream.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Encoding DotNet System.Text.Encoding.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Response Text
NoOfBytes Integer
Data DotNet System.Byte.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
SendCommand(IPAddress : Text[30];PortNo : Integer;MsgToSend : Text[50];VAR ResponseMsg : Text[50]) : Text
TCPDotNet := TCPDotNet.TcpClient(IPAddress, PortNo);
IF NOT TCPDotNet.Connected THEN BEGIN
ResponseMsg := STRSUBSTNO(NVP000, '');
EXIT(FALSE);
END;
// Send command
NetStream := TCPDotNet.GetStream;
NetStream.Write(Encoding.ASCII.GetBytes(MsgToSend), 0, Encoding.ASCII.GetBytes(MsgToSend).Length);
// Recieve response
Response := '';
NoOfBytes := NetStream.Read(Data, 0, 256);
Response := Encoding.GetString(Data, 0, NoOfBytes); // Error here when compiling - function call is ambiguous
NetStream.Close();
TCPDotNet.Close();
EXIT(Response);
Thank you in advance for any answer
I am having problems recieving response from TCP-server through dotnet-vars.
I am connecting to a TCP-server. Then I am sending a command to the TCP-server. When the TCP-server recieves the command it sends simple info back (just to make sure that the command from NAV has been recieved by the TCP-server).
I am able to send the command, but when I add code to recieve the response, I get compile error "Function call is ambiguous. No matching method found". Am I doing it wrong? Or is this not possible?
My code and vars goes here:
TCPDotNet DotNet System.Net.Sockets.TcpClient.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
NetStream DotNet System.Net.Sockets.NetworkStream.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Encoding DotNet System.Text.Encoding.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Response Text
NoOfBytes Integer
Data DotNet System.Byte.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
SendCommand(IPAddress : Text[30];PortNo : Integer;MsgToSend : Text[50];VAR ResponseMsg : Text[50]) : Text
TCPDotNet := TCPDotNet.TcpClient(IPAddress, PortNo);
IF NOT TCPDotNet.Connected THEN BEGIN
ResponseMsg := STRSUBSTNO(NVP000, '');
EXIT(FALSE);
END;
// Send command
NetStream := TCPDotNet.GetStream;
NetStream.Write(Encoding.ASCII.GetBytes(MsgToSend), 0, Encoding.ASCII.GetBytes(MsgToSend).Length);
// Recieve response
Response := '';
NoOfBytes := NetStream.Read(Data, 0, 256);
Response := Encoding.GetString(Data, 0, NoOfBytes); // Error here when compiling - function call is ambiguous
NetStream.Close();
TCPDotNet.Close();
EXIT(Response);
Thank you in advance for any answer

0
Comments
-
Hi, try something like this:
IF NOT lFloodMode THEN BEGIN lTcpClient.SendTimeout(pSyncSetup.Timeout); lOutStream := lTcpClient.GetStream; lOutStream.WRITETEXT('READ' + lCF.GetCRLF); END; lTcpClient.ReceiveTimeout(pSyncSetup.Timeout); lInStream := lTcpClient.GetStream; lInStream.READTEXT(lReceivedMessage);
Regards
xStepa0 -
I thnk you need to use an array if bytes, not a byte itself. I am reading and converting the data from TCP/IP stream into a text like this:
NETType := NETType.GetType('System.Byte',FALSE); ByteArr := ByteArr.CreateInstance(NETType, BufferLen); BytesRead := TCPNetworkStream.Read(ByteArr, 0, BufferLen); ReceivedMsg := NETEncoding.UTF8.GetString(ByteArr);
Where my NETType var is System.Type.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', the ByteArr var is System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and the NETEncoding var is the same type as yours Encoding
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031
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