Other Parts Discussed in Thread: OMAP-L137, TMS320C6747
Dear E2E!
I have the next problem:
Socket-function connect() hangs for a minute while reconnecting to the server.
I wrote my TCP-client application on the base of the helloWord NDK example.
After callback function "NetworkIPAddr" is launched, I try to connect to a TCP-server in the separate task. (NetworkIPAddr is the callback function of the NC_NetStart(), it is called after the device IP address is obtained or released ) Priority of the task is 4 (lower as NDK tasks).
In this task following operations are performed:
1) create the socket;
2) set timeouts of the socket;
3) set number of port of the local socket;
4) connect socket to a server
code listing see pleace in the end of message.
The first launch of the program succeeds every time. Connect() returns zero (OK!) and then program can communicate with TCP-server with send() and recv().
But when I stop program and then restart it (for example, my device is resetted due to the power supply switching), then the program will hang in "connect" function for a minute. Changing of the socket timeouts hasn't effect.
If I will change the local port number - all right, connect() succeeds again, but only for a one call of the connect().
It seems, that server after reset of my device has the opened part of the socket. It must be closed before my device call connect(). But how can I do this from my device using NDK API?
My platform:
TMS320C6747 EVM (OMAP-L137 EVM),
CCStudio3.3,
DSP/BIOS5.33.01
NDK 2.0.0
Thanks in advance!
Vitalii
-----------------------------
Listing of the task that initializes and connects socket:
SOCKET s;
struct sockaddr_in peer;
int rc;
struct timeval timeout;
struct sockaddr_in MySockProp;
int rc;
// Allocate the NDK file descriptor environment for this task
fdOpenSession( (HANDLE)TSK_self() ); // from NDK User's Guide "Developing Socket Applications with DSP/BIOS"
peer.sin_family = AF_INET;
peer.sin_port = htons( 4736 );
peer.sin_addr.s_addr = inet_addr( "192.168.1.200" );
peer.sin_len = sizeof( peer );
s = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( INVALID_SOCKET == s )
printf("Error during socket() \n");
timeout.tv_sec = 20;
timeout.tv_usec = 0;
if( -1 == setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) )
printf("Error when setting TIMEOUTs \n");
if( -1 == setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) )
printf("Error when setting TIMEOUTs \n");
MySockProp.sin_family = AF_INET;
MySockProp.sin_port = htons( 7777 );
MySockProp.sin_addr.s_addr = htonl( INADDR_ANY );
MySockProp.sin_len = sizeof( MySockProp );
if( -1 == bind( s, (struct sockaddr *)&MySockProp, sizeof(MySockProp) ) )
printf("Error when setting portNo of the local socket \n");
rc = connect( s, (struct sockaddr *)&peer, sizeof(peer) ); // if it succeeds, the function returns 0
if ( rc )
printf("Error during connect() \n");
if( 0 == n32ReturnValue )
printf("Connected to TCP Server \n");
fdCloseSession( (HANDLE)TSK_self() ); // NDK User's Guide "Developing Socket Applications with DSP/BIOS"
TSK_exit();