----- Original Message -----
Sent: Tuesday, March 09, 2010 3:35
PM
Subject: [lwip-users] netconn_x API,
Connecting a TCP client fails
I have succeeded
in setting up a server app using both, the Raw API and the netconn_x API. But
I also need a TCP client on my device in oder to send state information to a
connected server on a PC. And there I encounter a problem, or in other
words: I'm doing something wrong.
void EthClientTask
( void * aParam )
{
struct ipaddr xAddrRem, xAddrLoc;
xAddrRem.addr = M_IpAddrEncode ( 192, 168, 142, 52
); // server address (PC)
xAddrLoc.addr = M_IpAddrEncode ( 192, 168, 142, 55
); // local device
address
struct
netconn * xNetConn;
int
xRes;
Boolean
xIni = false;
while ( true )
{
RTOS_TaskSleep ( cT1s );
if ( !xIni
)
{
xNetConn = netconn_new (
NETCONN_TCP ); // handle NULL !
xRes = netconn_bind ( xNetConn,
&xAddrLoc, 9000
)
+
netconn_connect ( xNetConn, &xAddrRem, 9000 );
xIni = true;
}
if ( xRes == ERR_OK
)
netconn_write ( xNetConn, "Lorem ipsum",
11, NETCONN_NOCOPY );
// netconn_delete (
xNetConn );
}
}
This code actually
works, if the server does not close its client it got at connect
time.
But that's not
what I really want. The client task may have nothing to do for a long
time. But when there's something to do, it should open a connection and send
whatever is due and then close the connection again.
I thought, if I
remove the 'if (!xIni)' in the code above and uncomment the
'netconn_delete', it should work exactly the same (the server would have
to close its client and wait for a new connection).
But it doesn't.
The 'netconn_bind' returns with -11 (Address used), which I don't understand
because I delete the netconn and all the resources are released, aren't they?
Certainly there must be a way to properly close down the connection and reopen
it. Can anyone give me a hint? Thanks in advance!
Walter
_____________________________
SOLON Inverters AG
Burgerfeldstrasse
19
CH-8730 Uznach SG, Schweiz
Phone: +41 55 246 41
14
Direct: +41 55 246 58 52
Fax:
+41 55 246 41 16
www.solon.com