Socket Error while making tcp ip connection in delphi - delphi

I am using indy client to make tcp ip connection with a server(IP address and port). I have written following code on the click of a button. I trying to send Hello msg to server and then trying to read the message from server.
procedure TForm1.Button1Click(Sender: TObject);
var
sMsg : string;
begin
try
IdTCPClient1.Port := xxxx; //Set port to connect to
IdTCPClient1.Host := 'xxx.xxx.x.xxxx'; //Set host to connect to
IdTCPClient1.Connect; //Make connection
sMsg := IdTCPClient1.Socket.ReadLn; //Read the response from the server
ShowMessage(sMsg);
except
on E : Exception do
begin
ShowMessage('Connection Error: ' + E.Message);
exit;
end;
end;
end;
But I am getting socket error 10061 connection refused while debugging at the line
IdTCPClient1.Connect; //Make connection
I tried to make tcp connection with server on given port and ip using telnet command on cmd (telnet ip port) and I got the following message
"Connection established to xxx.xxx.xx.xxx, there could be no connection made ​​with the host, on port xxxx: connection errors"
Please suggest me the solution for this...
Thanks all. Now I am able to use the port. So no error at IdTCPClient1.Connect; //Make connection. But now nothing is happening at the next line where I am trying to read data from the server (sMsg := IdTCPClient1.Socket.ReadLn;) When I try from telnet, some miscellaneous characters are read from server. What could be the reason for this?

Related

PHPMailer & Mailhog: connection refused, host not known

trying to get Mailhog to run. i'm running a Neard stack and i haven't used Mailhog before. the docs are slim for somebody who isn't familiar with email services (finger pointing at self). here's what i have code-wise:
// create the instance
$mail = new PHPMailer;
$mail->isSMTP(); // i read somwhere that this may require commenting out to work...
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->Host = 'mail'; // i also tried 'localhost' here... same result
$mail->Port = 1025;
$mail->SMTPAuth = true;
$mail->Username = EMAILUSERNAME;
$mail->Password = EMAILPASSWORD;
$mail->setFrom($from, $senderName);
$mail->addReplyTo('blorp#blorp.blorp'); // obviously a placeholder
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHTML(file_get_contents(__DIR__.'\90days.php'));
// send the email and check for errors
if (!$mail->send()) {
echo 'Mail error: '. $mail->ErrorInfo;
} else {
echo 'Message sent Successfully';
}
running it through Postman, i get the following error:
2020-04-15 01:53:50 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mail error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
from what i understand from this post, all i had to do was set the Host and Port to the settings above and Mailhog would intercept. but it doesn't work. so what did i overlook or misconfigure?
I got the same error and I solved removing SMTPSecure
// $mail->SMTPSecure = 'tls';
Hope this helps someone else.

Indy TIdhttp.Get is not loading proper version of SSL

I am trying to make an interface to FreshDesk API
Here is my source code for the call:
procedure TForm1.Button1Click(Sender: TObject);
var
IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocketOpenSSL;
idhttp: TIdHttp;
begin
idhttp := TIdHttp.Create(self);
idhttp.Request.ContentType := 'application/json';
IdHTTP.Request.BasicAuthentication:= True;
IdHTTP.Request.Username := 'marks#mytestcompany.com';
IdHTTP.Request.Password := 'XYZ';
idhttp.Request.Connection:='keep-alive';
IdSSLIOHandlerSocket1 := TIdSSLIOHandlerSocketOpenSSL.create(nil);
with IdSSLIOHandlerSocket1 do begin
SSLOptions.Method := sslvTLSv1_2;
SSLOptions.SSLVersions := [sslvTLSv1_2];
SSLOptions.VerifyMode := [];
SSLOptions.VerifyDepth := 2;
end;
idhttp.IOHandler := IdSSLIOHandlerSocket1;
idhttp.Request.Accept := '*/*';
idhttp.HandleRedirects := True;
if usefiddler.checked then begin
idhttp.ProxyParams.ProxyServer := '127.0.0.1';
idhttp.ProxyParams.ProxyPort := 8888 ;
end;
showMessage(idhttp.get('https://mytestcompany.freshdesk.com/api/v2/contacts'));
end;
When I run using Fiddler it shows it is using Version: 3.1 (TLS/1.0):
Here is successful curl call (it seems to be using Version: 3.3 (TLS/1.2):
curl -v -u marks#mytestcompnay:XYZ -H "Content-Type: application/json" -X GET "https://mytestcompany.freshdesk.com/api/v2/contacts"
Here is Fiddler results when using curl:
Is my problem that I am using the wrong version of TLS?
You are using an outdated version of OpenSSL.
Per comments, you say that you are using OpenSSL 1.0.0q. That version is several years old and does not support TLS v1.2 (which was added to OpenSSL in 1.0.1, which is still an old version). Indy silently falls back to TLS v1.0 when it cannot use TLS v1.1 or v1.2.
You need to update your OpenSSL. The latest version of OpenSSL that Indy currently supports is 1.0.2.

How can we connect with a website? Getting SSL error 1409442E

I am using Delphi 10.2 Tokyo, trying to download some information from a web server.
I pass the command URL https://poloniex.com/public?command=returnCurrencies through this function using Indy 10.6.2.5366 (the command works if I paste it in a browser):
function ReadHTTPS(const url: string): string;
var
IdHTTP: TIdHTTP;
IdSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
IdHTTP := TIdHTTP.Create;
try
IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
IdHTTP.IOHandler := IdSSL;
result := IdHTTP.Get(url);
if IdHTTP.ResponseText <> '' then
OutputDebugString(PWideChar('ReadHTTPS: ' + IdHTTP.ResponseText));
finally
IdHTTP.Free;
end;
end{ ReadHTTPS};
That gives the following error:
Error connecting with SSL.
error:1409442E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol version
I have tried installing the latest DLLs for OpenSSL in the same directory as the exe, but that didn't solve it.
Any ideas?
Make sure you are using an up-to-date version of the OpenSSL DLLs that support TLS v1.2 (the latest version that Indy currently supports is 1.0.2u), and then you need to enable the sslvTLSv1_2 flag in the SSLIOHandler's SSLOptions.SSLVersions property:
IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
Or:
IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_2];
Indy enables only TLS v1.0 by default, and apparently https://poloniex.com does not allow TLS versions prior to TLS v1.2.

Error while connecting to port 1883

I have a Rpi-A connected to internet via 3G surf-stick and Rpi-B connected to internet via a WiFi hotspot. Rpi-A has a public ip address and also ports 1883 and 8883 are open. Both raspberry Pi's are on different networks. I am attempting to send binary data using MQTT from Rpi-B to Rpi-A.
update: I used the below code to test the MQTT connection. replacing XX.XX.XX.XX with public IP of raspberry Pi. Still I end up getting this error--->
error: [Errno 10060] A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.
what might be the possible reason for this error ? Is there anything missing in my code
import paho.mqtt.client as mqtt
import time
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client = mqtt.Client()
client.on_connect = on_connect
client.connect("xx.xx.xxx.x", 1883, 60)
client.loop_start()
while True:
time.sleep(2)
client.publish('Due_0.72/cmd/in','hello')
print "publish.."

Delphi 10.2 FTP SSL

Here's my program
ftp := TIdFTp.Create();
IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(ftp);
with IdSSLIOHandlerSocketOpenSSL1 do
begin
host := fhost;
MaxLineAction := maException;
port := 2111;
ReadTimeout := 60000;
SSLOptions.Method := sslvSSLv3;
SSLOptions.Mode := sslmUnassigned;
end;
ftp := TIdFTp.Create();
with ftp do
begin
Host := fHost;
password := fpass;
Username := fuser;
IOHandler :=IdSSLIOHandlerSocketOpenSSL1;
UseTLS := utUseExplicitTLS;
DataPortProtection := ftpdpsPrivate;
port := 2111;
end;
ftp.Connect;
I'm using TIdFTP component in Delphi 2007 and Delphi 10.2 Berlin.
For Delphi 2007, the program connects to FTP. However, for the Delphi 10.2 the program gives an error 'Could not load SSL library.'
In both cases, to the exe file directory I include the ssleay32.dll and libeay32.dll files

Resources