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
Comments
xStepa
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Thank you very much for taking your time on posting reply.
@Slawek - I tried your solution and it worked perfectly - thank you very very much - I highly appreciate it. Thank you