Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: More IdTCPClient connection issues



Permlink Replies: 4 - Last Post: Nov 17, 2016 1:25 PM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Colin Maharaj

Posts: 122
Registered: 12/2/99
More IdTCPClient connection issues
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 16, 2016 4:47 PM
So, I have an Indy v10 TCP Client connecting to a device to collect
data, straight forward.

Now this code is in a very complex console app, however what happens
is that it disconnects for no apparent reason, and just gets a read
timeout after reading about 600 bytes.

Also the TCP server is an Indy10 line by line reader from a text
file that is sent to the Client, but pauses for about 500 ms every
time a line is sent.

The thing is, I have this running under wine in Linux.

Now If I do a native Linux tcp receiver in C
or
a native tcp receiver in C in windows and run it in
wine, it works fine.

I am literally doing the low level........

sockfd = socket(AF_INET, SOCK_STREAM, 0);
etc, to make the connection and get data

Any suggestions?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: More IdTCPClient connection issues
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 16, 2016 7:35 PM   in response to: Colin Maharaj in response to: Colin Maharaj
Colin wrote:

So, I have an Indy v10 TCP Client connecting to a device to collect
data, straight forward.

What kind of data exactly?

Now this code is in a very complex console app, however what happens
is that it disconnects for no apparent reason, and just gets a read
timeout after reading about 600 bytes.

There is always a reason. You just have to figure out what it is. The only
way a disconnect should be causing a read timeout error is if the connection
is lost abnormal (network reset, device power off, etc), or you are not handling
the timeout correctly in your code. Can you please show some actual code?

Also the TCP server is an Indy10 line by line reader from a text file
that is sent to the Client, but pauses for about 500 ms every time a
line is sent.

You said the server is on a device. Now you are saying you have your own
server? Which is it?

--
Remy Lebeau (TeamB)
Colin Maharaj

Posts: 122
Registered: 12/2/99
Re: More IdTCPClient connection issues
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 17, 2016 3:33 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Ok, I will clarify,

On 16/11/2016 11:35 PM, Remy Lebeau (TeamB) wrote:
Colin wrote:

So, I have an Indy v10 TCP Client connecting to a device to collect
data, straight forward.

What kind of data exactly?

Mainly plain text, but I like to treat all my incoming streams as binary.

Now this code is in a very complex console app, however what happens
is that it disconnects for no apparent reason, and just gets a read
timeout after reading about 600 bytes.

There is always a reason. You just have to figure out what it is. The only
way a disconnect should be causing a read timeout error is if the connection
is lost abnormal (network reset, device power off, etc), or you are not handling
the timeout correctly in your code. Can you please show some actual code?

Doing it in test environment, and it consistently happens, like I said a vanilla
tcp client with native C code holds up, even native telnet in Linux and Windows
hold up.

The problem with this situation is that if I write plain code even plain
IdTCPClient code it works! But, in the project I have it does not work.

But you maybe right, there is something going on in the app that I may not
be aware of, I may have to figure it out. I will create a small project
to emulate.

Or restart the project and add file by file until I see whats happening.

Also the TCP server is an Indy10 line by line reader from a text file
that is sent to the Client, but pauses for about 500 ms every time a
line is sent.

You said the server is on a device. Now you are saying you have your own
server? Which is it?

So , I don't have the device, but the device sends line-by-line plain text when
you telnet to it. It is real time / event data, so it may pause for long times from
time to time. In the night, there may be no data at all. So I created an emulator.

Telnet to the emulator using windows and linux telnet works,
as well as the plain C tcp receivers.

Works means that while I may get a timeout, and I know a timeout is not an error
It will exit recv (windows) or read (Linux) and I just loop back to those functions
to get more data.

I did this for the timeout.

struct timeval timeo; timeo.tv_sec = 0; timeo.tv_usec = 500; // 0.5 secs time out
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeo, sizeof(timeo));


Thanks for your support, so far.

Colin Maharaj

Posts: 122
Registered: 12/2/99
Re: More IdTCPClient connection issues
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 17, 2016 3:34 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Ok, I will clarify,

On 16/11/2016 11:35 PM, Remy Lebeau (TeamB) wrote:
Colin wrote:

So, I have an Indy v10 TCP Client connecting to a device to collect
data, straight forward.

What kind of data exactly?

Mainly plain text, but I like to treat all my incoming streams as binary.

Now this code is in a very complex console app, however what happens
is that it disconnects for no apparent reason, and just gets a read
timeout after reading about 600 bytes.

There is always a reason. You just have to figure out what it is. The only
way a disconnect should be causing a read timeout error is if the connection
is lost abnormal (network reset, device power off, etc), or you are not handling
the timeout correctly in your code. Can you please show some actual code?

Doing it in test environment, and it consistently happens, like I said a vanilla
tcp client with native C code holds up, even native telnet in Linux and Windows
hold up.

The problem with this situation is that if I write plain code even plain
IdTCPClient code it works! But, in the project I have it does not work.

But you maybe right, there is something going on in the app that I may not
be aware of, I may have to figure it out. I will create a small project
to emulate.

Or restart the project and add file by file until I see whats happening.

Also the TCP server is an Indy10 line by line reader from a text file
that is sent to the Client, but pauses for about 500 ms every time a
line is sent.

You said the server is on a device. Now you are saying you have your own
server? Which is it?

So , I don't have the device, but the device sends line-by-line plain text when
you telnet to it. It is real time / event data, so it may pause for long times from
time to time. In the night, there may be no data at all. So I created an emulator.

Telnet to the emulator using windows and linux telnet works,
as well as the plain C tcp receivers.

Works means that while I may get a timeout, and I know a timeout is not an error
It will exit recv (windows) or read (Linux) and I just loop back to those functions
to get more data.

I did this for the timeout.

struct timeval timeo; timeo.tv_sec = 0; timeo.tv_usec = 500; // 0.5 secs time out
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeo, sizeof(timeo));


Thanks for your support, so far.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: More IdTCPClient connection issues
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 17, 2016 1:25 PM   in response to: Colin Maharaj in response to: Colin Maharaj
Colin wrote:

Mainly plain text, but I like to treat all my incoming streams as
binary.

I ask because the format of the data dictates how you can read it with
Indy. Indy has many different reading methods for different kinds of data
formats. Maybe you are reading the data incorrectly, causing errors. Hard
to say since you have not shown what the data or the socket code look like
yet.

Doing it in test environment, and it consistently happens, like I said
a vanilla tcp client with native C code holds up, even native telnet
in Linux and Windows hold up.

That is not helpful information to diagnose the problem. Can you please
answer the questions I ask? I'm not asking them for no reason.

The problem with this situation is that if I write plain code even
plain IdTCPClient code it works! But, in the project I have it does
not work.

Then you are clearly doing something different between the two projects.
What is different?

So , I don't have the device, but the device sends line-by-line plain
text when you telnet to it. It is real time / event data, so it may
pause for long times from time to time. In the night, there may be
no data at all. So I created an emulator.

An emulater can simulate the same data, but not necessarily the same network
conditions.

Works means that while I may get a timeout, and I know a timeout is
not an error
It will exit recv (windows) or read (Linux) and I just loop back to
those functions to get more data.

Depending on what kind of reading code you are using, Indy may or may not
treat a read timeout as an error, throwing an exception like EIdReadTimeout.
Are you accounting for that? Again, please show some actual code that you
are having problems with.

I did this for the timeout.

struct timeval timeo; timeo.tv_sec = 0; timeo.tv_usec = 500; // 0.5 secs
time out
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeo, sizeof(timeo));

Indy uses select() to implement its ReadTimeout, it does not use SO_RCVTIMEO.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02