Hello,
I have a Client TCP Socket application that makes a connection to a server.
The application is just connecting to the server port, sends some data and following the data, the server returns some result.
The Client application is using blocking socket and it's working great.
Unfortunately, sometimes, the TCP connection is lost and thus the Client application stays "frozen" on the recv call.
So, my idea was to set to non-blocking the recv call.
Now, the result received should be 128 characters or finished by a specific character.
c dou reclen = 128 or ch = x'03' or ch = x'08'
c eval rc = recv(sock: %addr(ch): 1: 0)
Is the non-blocking solution on the recv the good solution to have an error recovery and to recreate the socket ?
If yes, I'm a little bit lost how to imlement it. I went through Scott document and his examples... but I don't understand it very well.
I read the following: "Non-blocking sockets can also be used in conjunction with the select() API. In fact, if you reach a point where you actually WANT to wait for data on a socket that was previously marked as "non-blocking", you could simulate a blocking recv() just by calling select() first, followed by recv()."
So should I call in the following order:
- the fcntl() API to set the socket in non-blocking
- the select() API to wait for data
- the recv() to receive the data
- the fcntl() API to reset the socket in blocking mode ?
What I don't understand is should I include the select in the DOU loop ?
Do you have a small and easy example of just a client program in non-blocking mode that send and recv a data ?
Thanks in advance for your support.
Best regards,
Pierre
I have a Client TCP Socket application that makes a connection to a server.
The application is just connecting to the server port, sends some data and following the data, the server returns some result.
The Client application is using blocking socket and it's working great.
Unfortunately, sometimes, the TCP connection is lost and thus the Client application stays "frozen" on the recv call.
So, my idea was to set to non-blocking the recv call.
Now, the result received should be 128 characters or finished by a specific character.
c dou reclen = 128 or ch = x'03' or ch = x'08'
c eval rc = recv(sock: %addr(ch): 1: 0)
Is the non-blocking solution on the recv the good solution to have an error recovery and to recreate the socket ?
If yes, I'm a little bit lost how to imlement it. I went through Scott document and his examples... but I don't understand it very well.
I read the following: "Non-blocking sockets can also be used in conjunction with the select() API. In fact, if you reach a point where you actually WANT to wait for data on a socket that was previously marked as "non-blocking", you could simulate a blocking recv() just by calling select() first, followed by recv()."
So should I call in the following order:
- the fcntl() API to set the socket in non-blocking
- the select() API to wait for data
- the recv() to receive the data
- the fcntl() API to reset the socket in blocking mode ?
What I don't understand is should I include the select in the DOU loop ?
Do you have a small and easy example of just a client program in non-blocking mode that send and recv a data ?
Thanks in advance for your support.
Best regards,
Pierre
Comment