i am working on FRDMk64 controller. i am using KDS 2.0 and KSDK1.1.0 IDE.
can you tel how to change or set KEEP_ALIVE_TIMEOUT for socket. if you tell API function
its helpful to me.
thanks ang regards,
You must use setsockopt() and the option is OPT_KEEPALIVE.
You can find it in Reference Manual:
You can find it in installation path depending if you use classic MQX or MQX for KSDK:
actually i have two socket. i am listening 7727 and 7728 port. so i want to set different timeout for each socket.
is possible? if possible how to set different time in following API function.
"retval = setsockopt(client_sock, SOL_TCP,OPT_KEEPALIVE, &option, sizeof(option));
using above function how can i set different keeplive.
thanks and regards,
when you use function socket() to create a new socket it returns a Socket handle which is the first parameter used by setsockopt(). So you need to save this each socket handle in different variables to use them with setsockopt() and set a different value in each case.
thank you.i have one doubt,here
setsockopt(client_sock, SOL_TCP,OPT_KEEPALIVE, &option, sizeof(option));
in above API function instead of OPT_KEEPALIVE can i directly pass 60000 or 30000 (for 1-minute and 30 sec)
i am using different socket handle only. but my question was, just assume i am passing any one parameter below,
#define OPT_CONNECT_TIMEOUT 0x01
#define OPT_RECEIVE_NOWAIT 0x09
#define OPT_KEEPALIVE 0x10
#define OPT_TIMEWAIT_TIMEOUT 0x17
and also default time values also defined in rtcs.h file.like Connect Timeout
(OPT_CONNECT_TIMEOUT) 8minute like that. so how it will take corresponding time?is 0x09 or 0x10 or 0x17 have relationship with anyother?.
i gone throught RTCS document also
Option name: OPT_KEEPALIVE
Protocol level :SOL_TCP
Values • Zero (RTCS does not probe the remote endpoint).
• Non-zero (if the connection is idle, RTCS periodically probes the
remote endpoint, an action that detects, whether the remote
endpoint is still present).
Default value : Zero minutes
Change: Before bound
Socket type : Stream
Comments : The option is not a standard feature of the TCP/IP specification and
generates unnecessary periodic network traffic.
I am not sure if I got your question, but you need to set OPT_KEEPALIVE macro in the third parameter which is indicates the name of the option and in the 4th parameter which is option value is where you set the amount of minutes you want.
i tried following steps
client_sock= accept(conn_sock, &remote_sin, &remote_addrlen);
option =60000;//for 1 minute
retval = setsockopt(client_sock, SOL_TCP, OPT_KEEPALIVE,&option, sizeof(option));
if (retval != RTCS_OK)
fputs("Fatal Error: Unable to set socket options.", stderr);
but after 1MINUTE its not disconnect the connection. still connection was there. why?. actually i want after some time the connection should shutdown if no data transfer between particular time. if i am doing anything wrong just correct me.
keepalive option does the opposite of what you need. It send zero length packets to keep connection alive.
You may check Timewait Timeoutand close/shut the socket manually after validating what this function returned.
As I told before ou can use function setsockopt() to manage sockets timeouts. These timeouts are declared in tcp_prv.h on RTCS project.
#define TCP_MSL 120000L /* Maximum Segment Lifetime; the
longest time that a packet can
travel in the Internet (2 min) */
#define TCP_WAITTIMEOUT (2 * TCP_MSL) /* timeout for TIME_WAIT state, defined
as 2 * MSL (4 min) */
#define TCP_SENDTIMEOUT_MIN 100000L /* as per RFC1122 18.104.22.168 */
#define TCP_OPENTIMEOUT_MIN 180000L /* as per RFC1122 22.214.171.124 */
But you can override these values with setsockopt().
thanks for your reply.
but i dnt know which Timeout i want to use exactly. actually i want after some time(whatever configured time)if there is no data transfer between socket ,its should be automatically close the connection. so how to do that one. please mention with example (only setsockopt() API example). i gone through tcp_prv.h file also.
Retrieving data ...