socket in mql5 why "not work" the example ?

 

Hi i try to understund the socket in mql5 i take a example in help , i run it  and  return me

2024.11.09 12:06:39.109 TCP_PASS_DATA (EURUSD,H1)       Established connection to www.mql5.com:80
2024.11.09 12:06:39.109 TCP_PASS_DATA (EURUSD,H1)       GET request sent
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       HTTP answer header received:
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       HTTP/1.1 301 Moved Permanently
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       Server: Angie
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       Date: Sat, 09 Nov 2024 11:06:38 GMT
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       Content-Type: text/html
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       Content-Length: 162
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       Connection: keep-alive
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       Location: https://www.mql5.com/
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
2024.11.09 12:06:39.151 TCP_PASS_DATA (EURUSD,H1)       X-Frame-Options: SAMEORIGIN

a this point i open my netcat in listen mode in local host over port 8080 >nc -l -p 8080

and i modify the  code insert 127.0.0.1 like address and port 8080  i suppose i must  see a try to connect in netcat and get string sended by mql5 , but  return:

2024.11.09 12:10:14.756    TCP_PASS_DATA (EURUSD,H1)    Connection to 127.0.0.1:8080 failed, error 4014

why ? ?

my code

//+------------------------------------------------------------------+ 
//|                                                SocketExample.mq5 | 
//|                        Copyright 2018, MetaQuotes Software Corp. | 
//|                                             https://www.mql5.com | 
//+------------------------------------------------------------------+ 
#property copyright   "Copyright 2000-2024, MetaQuotes Ltd." 
#property link        "https://www.mql5.com" 
#property version     "1.00" 
#property description "Add Address to the list of allowed ones in the terminal settings to let the example work" 
#property script_show_inputs 
  
input string Address="127.0.0.1"; 
input int    Port   =8080; 
bool         ExtTLS =false; 
//+------------------------------------------------------------------+ 
//| Send command to the server                                       | 
//+------------------------------------------------------------------+ 
bool HTTPSend(int socket,string request) a
  { 
   char req[]; 
   int  len=StringToCharArray(request,req)-1; 
   if(len<0) 
      return(false); 
//--- if secure TLS connection is used via the port 443 
   if(ExtTLS) 
      return(SocketTlsSend(socket,req,len)==len); 
//--- if standard TCP connection is used 
   return(SocketSend(socket,req,len)==len); 
  } 
//+------------------------------------------------------------------+ 
//| Read server response                                             | 
//+------------------------------------------------------------------+ 
bool HTTPRecv(int socket,uint timeout) 
  { 
   char   rsp[]; 
   string result; 
   uint   timeout_check=GetTickCount()+timeout; 
//--- read data from sockets till they are still present but not longer than timeout 
   do 
     { 
      uint len=SocketIsReadable(socket); 
      if(len) 
        { 
         int rsp_len; 
         //--- various reading commands depending on whether the connection is secure or not 
         if(ExtTLS) 
            rsp_len=SocketTlsRead(socket,rsp,len); 
         else 
            rsp_len=SocketRead(socket,rsp,len,timeout); 
         //--- analyze the response 
         if(rsp_len>0) 
           { 
            result+=CharArrayToString(rsp,0,rsp_len); 
            //--- print only the response header 
            int header_end=StringFind(result,"\r\n\r\n"); 
            if(header_end>0) 
              { 
               Print("HTTP answer header received:"); 
               Print(StringSubstr(result,0,header_end)); 
               return(true); 
              } 
           } 
        } 
     } 
   while(GetTickCount()<timeout_check && !IsStopped()); 
   return(false); 
  } 
//+------------------------------------------------------------------+ 
//| Script program start function                                    | 
//+------------------------------------------------------------------+ 
void OnStart() 
  { 
   int socket=SocketCreate(); 
//--- check the handle 
   if(socket!=INVALID_HANDLE) 
     { 
      //--- connect if all is well 
      if(SocketConnect(socket,Address,Port,1000)) 
        { 
         Print("Established connection to ",Address,":",Port); 
  
         string   subject,issuer,serial,thumbprint; 
         datetime expiration; 
         //--- if connection is secured by the certificate, display its data 
         if(SocketTlsCertificate(socket,subject,issuer,serial,thumbprint,expiration)) 
           { 
            Print("TLS certificate:"); 
            Print("   Owner:  ",subject); 
            Print("   Issuer:  ",issuer); 
            Print("   Number:     ",serial); 
            Print("   Print: ",thumbprint); 
            Print("   Expiration: ",expiration); 
            ExtTLS=true; 
           } 
         //--- send GET request to the server 
         if(HTTPSend(socket,"GET / HTTP/1.1\r\nHost: www.mql5.com\r\nUser-Agent: MT5\r\n\r\n")) 
           { 
            Print("GET request sent"); 
            //--- read the response 
            if(!HTTPRecv(socket,1000)) 
               Print("Failed to get a response, error ",GetLastError()); 
           } 
         else 
            Print("Failed to send GET request, error ",GetLastError()); 
        } 
      else 
        { 
         Print("Connection to ",Address,":",Port," failed, error ",GetLastError()); 
        } 
      //--- close a socket after using 
      SocketClose(socket); 
     } 
   else 
      Print("Failed to create a socket, error ",GetLastError()); 
  } 
//+--------------
 
Try localhost instead of IP.
 
Under windows, your server might listen on ::1 (IPv6) instead of 127.0.0.1 (IPv4).

Try to bind to 127.0.0.1 specificly in your server code.

good luck.