client.connect(server,port) always returns true

Hi all,
Even if I don't have any server running on arduino,

IPAddress server(192,168,1,3);
client.connect(server,23)

is returning true.
Why is it so ?
How can I avoid that ?

Did any one else faced similar problem ?

Thanks in advance

Regards,
Swaroop

That is client code. The server runs on the other device.

SurferTim:
That is client code. The server runs on the other device.

That is correct. But I am not running anything on other device.

Ok here is bigger picture,
I have ethernet switch. I connected (2 devices) a arduino due and a Yun to the ethernet switch. The server address is ethernet IP address of Yun. But currently on Yun i have not uploaded a sketch. It's just having a blink LED sketch. Whereas on the Due I am running above simple commands, and client.connect is always returning true even though there is no server running right now on Yun.

So that's why I am unable to figure out why it's returning true always ?

Are you certain there is no telnet server running on the Yun?

SurferTim:
Are you certain there is no telnet server running on the Yun?

Ok so here is the testing procedure:

  1. First I run the telnet server program on Yun.
  2. Now the client.connect returns true value - (This is fine) (On Due)
  3. Now I run the blink led program on yun.
  4. But now still client.connect returns true value. (Which is wrong or I don't want ) (On Due)

Is there something I am missing ? I mean even though I over written the sketch on Yun, will the telnet server be running in background once it was started due to the previous code?
If yes, then how can I stop it ? Is there any command I need to run to stop the server ?

Have you tried connecting to the Yun with a telnet client on your PC?

SurferTim:
Have you tried connecting to the Yun with a telnet client on your PC?

Sorry but I didn't get it, what do you meant by telnet client on PC
?
I got connected to Yun using Telnet client code from Arduino Due.

So the telnet server is running on the Yun? If so, what is the problem? The Due is connecting as a client to the Yun's telnet server.
.

Client.connect() does not return true or false. It returns an integer indicating success or error:

  • SUCCESS 1
  • TIMED_OUT -1
  • INVALID_SERVER -2
  • TRUNCATED -3
  • INVALID_RESPONSE -4

All of those integer return values are considered “true” inside an “if” statement because they are non-zero.

christop:
Client.connect() does not return true or false. It returns an integer indicating success or error:

  • SUCCESS 1
  • TIMED_OUT -1
  • INVALID_SERVER -2
  • TRUNCATED -3
  • INVALID_RESPONSE -4

All of those integer return values are considered "true" inside an "if" statement because they are non-zero.

Only if you use a domain name for the server. If you use an IP, it returns either true (1) or false (0).

swaroop2011:
Is there something I am missing ? I mean even though I over written the sketch on Yun, will the telnet server be running in background once it was started due to the previous code?

The Yun is (essentially) two devices on a single board, connected by an internal software 'bridge'. On one side of the bridge, you have an Atheros 'System on Chip' running a Linux distribution. On the other side of the bridge is an Arduino Leonardo, running an Arduino 'sketch.' Uploading a new sketch has no effect on the Linux side of the bridge.

If yes, then how can I stop it ? Is there any command I need to run to stop the server ?

The Telnet daemon is Linux! There are a number of ways to stop a daemon service starting up in Linux. Probably the easiest on the Yun is to disable the service through the Luci web configurator.

You might get more help in the Yun specific forum. Especially with the Linux-ness.

SurferTim:
Only if you use a domain name for the server. If you use an IP, it returns either true (1) or false (0).

https://www.arduino.cc/en/Reference/ClientConnect

If that’s the case, it’s poorly documented as it does not mention anything about a return value of 0.

Thanks all for their comment

SurferTim:
So the telnet server is running on the Yun? If so, what is the problem? The Due is connecting as a client to the Yun's telnet server.

The problem is, I have started the server on yun first by uploading server code. Then I overwrite it by uploading blink-Led sketch. So i thought that server won't exist anymore now. But as

MattS-UK:
The Yun is (essentially) two devices on a single board, connected by an internal software 'bridge'. On one side of the bridge, you have an Atheros 'System on Chip' running a Linux distribution. On the other side of the bridge is an Arduino Leonardo, running an Arduino 'sketch.' Uploading a new sketch has no effect on the Linux side of the bridge.

I believe uploading new sketch is not having any effect on linux side operations.

Then I need a way to stop the server by using some command in the code ?

christop:
Client.connect() does not return true or false. It returns an integer indicating success or error:

  • SUCCESS 1
  • TIMED_OUT -1
  • INVALID_SERVER -2
  • TRUNCATED -3
  • INVALID_RESPONSE -4

All of those integer return values are considered "true" inside an "if" statement because they are non-zero.

I even tried if(client.connect(server,23) == 1) , so it was always returning 1.

So if anyone has any ideas how to stop the server on linux part of yun will be helpful. As Matt suggested i will post this particular thing in Yun forum.

Post the question in the Yun section.

Yes, the documentation for the connect function is not complete. I tried to get it fixed, but I felt like a dog chasing its tail.