Jump to content
Dominik99

Delphi TClientSocket can't connect to Arduino server, Socket error: 10061

Recommended Posts

Hi!

 

So I made a Websocket server on my Arduino and i try to connect to that with a Delphi 11 program. I use TClientSocket to do that. I wrote a testprogram in Python and everything worked fine, so the problem isn't on hte Arduino's side. The Arduino's IP address is: 192.168.0.24. I also tried the Address like these: 192.168.0.24:6667, ws://192.168.0.24, ws://192.168.0.24:6667. I try to configure the TClientSocket like that: 

Client := TClientSocket.Create(nil);
Client.ClientType := ctNonBlocking;
Client.host := 'localhost';
Client.Address := '192.168.0.24';
Client.Port := 6667;
Client.Open;

This is in a btnClick event. What am I doing wrong?

Share this post


Link to post

Windows socket error 10061 is a Connection refused error sent to you by the target machine.

This means your Arduino server is not running or not listening on the TCP socket you think.

Your client may be faulty by using the wrong port or wrong IP or blocked by a firewall rule.

 

Share this post


Link to post

Yes. Finally figured out, that the Delphi software wants to connect to an Ethernet server not to a Websocket server. Is there any package in Delphi to connect to a Websocket server?

Edited by Dominik99

Share this post


Link to post

Ethernet is not TCP/IP.

Ethernet is a much lower level that TCP/IP. On a PC, when using TCP/IP, it almost always use Ethernet as lower level transport protocol.

Tell us more about what you are EXACTLY using on your Arduino board and which model of Arduino board you are using so that we better understand what you are trying to do.

 

Share this post


Link to post
8 hours ago, Dominik99 said:

I made a Websocket server on my Arduino and i try to connect to that with a Delphi 11 program. I use TClientSocket to do that. I wrote a testprogram in Python and everything worked fine, so the problem isn't on hte Arduino's side.

TClientSocket is just a thin wrapper around a TCP socket.  WebSocket is a protocol that runs on top of TCP.  Thus, TClientSocket will happily connect to a WebSocket server... when used correctly, which you are not...

8 hours ago, Dominik99 said:

The Arduino's IP address is: 192.168.0.24

But that is not the IP you are trying to connect to...

8 hours ago, Dominik99 said:

I try to configure the TClientSocket like that: 

...

Client.host := 'localhost';
Client.Address := '192.168.0.24';
...

This is where your mistake is.  The Host and Address properties are mutually exclusive, you can only use one of them.  The Host has priority over the Address.  So, you are trying to connect to 'localhost' (ie 127.0.0.1) only.  That is why you are getting an error, since there is no TCP server running on port 6667 on your local machine.

 

You need to either 1) drop the assignment of the Host altogether and just use the Address, or else 2) set the Host to the Arduino's hostname/IP:

Client.Host := '192.168.0.24';
7 hours ago, Dominik99 said:

Yes. Finally figured out, that the Delphi software wants to connect to an Ethernet server not to a Websocket server.

As far as TClientSocket is concerned, there is no difference.  It only knows about TCP, not any protocols on top of TCP (Ethernet is underneath), so if you continue using TClientSocket then you are going to have to implement the WebSocket protocol yourself from scratch.  Read RFC 6455 for that.  Otherwise, there are plenty of 3rd party WebSocket libraries available that you can use instead.

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×