Best is to use loopback, but if you need to know your device IP, you could either use this :
//GetsspecificinterfaceIPaddressFUNCTIONGetOwnIp : STRING(15)//ReturnsIPaddressfromselectedadapter. NeedSysSocketlibraryVAR_INPUT
  IndexOfAdapter : INT :=0; // Index of the ethernet adapter to get IP from (base 0) END_VARVAR
  sHostName  : STRING; // Own hostname
  Host : SysSocket.SOCK_HOSTENT; // Own host description
  pIPAddress : POINTERTODWORD; // Pointer to INADDR containing IP address
  in_addr   : INADDR; // Strong typed INADDR containing IP address
  sIPAddress : STRING; // IP address in string formatEND_VAR(*Getownhostname. *)SysSockGetHostName(szHostName:=sHostName, diNameLen:=SIZEOF(sHostName));(*GetownIPaddressbyitsname. *)SysSockGetHostByName(szHostName:=sHostName,pHost:=ADR(Host));(*Getadressoffirstadapter*)pIPAddress :=Host.pAddrList[IndexOfAdapter];(*CastpointerdatatoINADDRtype*)in_addr.ulAddr :=pIPAddress^;(*Getstringformat*)SysSockInetNtoa(pInAddr :=ADR(in_addr),szIPADDR :=sIPAddress, diIPAddrSize:=SIZEOF(sIPAddress));(*Functionreturn*)GetOwnIp:=sIPAddress;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello.
I'm using , and would like to use 'localhost' as the "" input.
https://help.codesys.com/webapp/RL4Lo8oYYkL-EiF1HG7hca7bLAI%2FTCP_Server;product=CAA_NetBaseServices;version=3.5.14.0
How can this be done? What is the best way to read this operating-system's variable?
Should I use a different library?
Thank you.
P.S.
Would it be easier if I wrote the specific IP address in an *.XML file and read it from there?
If so, do codesys has an XML library?
Thanks
Could you just use the loopback address 127.0.0.1?
Best is to use loopback, but if you need to know your device IP, you could either use this :