lwIP Wiki
Advertisement

netconn_connect[]

err_t netconn_connect ( struct netconn * aNetConn, 
                        ip_addr_t * aAddr, u16_t aPport );
  • in aNetConn : netconn structure received by netconn_new or netconn_accept.
  • in aAddr : the IP address of the remote server to connect to
  • in aPort : the port of the remote server to connect to

Attempt to establish a connection between the local client and a remote server.

Example of a client:


struct netconn *xNetConn = NULL;

struct ip_addr local_ip; 
struct ip_addr remote_ip; 
int rc1, rc2; 
 
xNetConn = netconn_new ( NETCONN_TCP ); 
 
if ( xNetConn == NULL ) { 
 
 /* No memory for new connection? */
 continue;
}

local_ip.addr = <get IP of this device>

rc1 = netconn_bind ( xNetConn, &local_ip, 0 ); 
 
remote_ip.addr = xRemoteIp; // static or by netconn_gethostbyname ()
rc2 = netconn_connect ( xNetConn, &remote_ip, cClientPort ); 
 
if ( rc1 != ERR_OK || rc2 != ERR_OK )
{

  netconn_delete ( xNetConn );
 continue;
}

(last changed: August 2, 2011)

Advertisement