<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF9160 TCP connect errno -116</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76398/nrf9160-tcp-connect-errno--116</link><description>Shalom! 
 I am getting with the nRF9160, BSD TCP sockets, a connect() errno=116 after disconnecting and closing a previous TCP connection. 
 I have two TCP servers with the same IP just different ports. When I switch to the second one, I get this error</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Jun 2021 07:05:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76398/nrf9160-tcp-connect-errno--116" /><item><title>RE: nRF9160 TCP connect errno -116</title><link>https://devzone.nordicsemi.com/thread/316168?ContentTypeID=1</link><pubDate>Mon, 21 Jun 2021 07:05:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10849790-3ad5-401f-8a83-8c32be5908ad</guid><dc:creator>DavidKaplan</dc:creator><description>&lt;p&gt;Shalom!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;This morning we found my problem. I was checking the errno after calling the blocking_connect() function even when the err returned from connect() was zero therefore I was closing the socket. Now the modem seems to re-connect to our TCP server.&lt;/p&gt;
&lt;p&gt;Thank you very much&lt;/p&gt;
&lt;p&gt;&amp;nbsp;David&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//-----------------------------------------------------------------------------
// connect_to_cloud
//  Description
//    Tries to connect to the Cloud
//  Parameters
//  Returns
//   ami_socket_connect_result
//-----------------------------------------------------------------------------
static int connect_to_cloud(void)
{
  atomic_set(&amp;amp;disconnect_requested, 0);

  struct sockaddr    local_addr;
  int                err;
  char               sIPPort[24];

  sprintf(sIPPort,&amp;quot;%u.%u.%u.%u:%u&amp;quot;,
      cur_server.server_ip.bytes[MSB_HI_BYTE],
      cur_server.server_ip.bytes[MSB_LO_BYTE],
      cur_server.server_ip.bytes[LSB_HI_BYTE],
      cur_server.server_ip.bytes[LSB_LO_BYTE],
      cur_server.server_port.word
   );
  //---------------------------------------------------------------------------
  // Parse the IP:Port string
  //---------------------------------------------------------------------------
  if (!net_ipaddr_parse((const char *)sIPPort,strlen(sIPPort),&amp;amp;local_addr)){
    d_printf(LINE_INFO,kDbg_Error|kDbg_General,&amp;quot;ServerIP:PortParsingErr&amp;quot;);
    return AMI_SOCKET_CONNECT_RES_ERR_NOT_INITD;
  }
  //---------------------------------------------------------------------------
  // Close socket if opened
  //---------------------------------------------------------------------------
  if (app_socket_fd&amp;gt;=0){
    close(app_socket_fd);
  }
  //---------------------------------------------------------------------------
  // Create a TCP socket
  //---------------------------------------------------------------------------
  app_socket_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  d_printf(LINE_INFO,kDbg_Info|kDbg_General,&amp;quot;SocketFD:%d&amp;quot;,app_socket_fd);
  //---------------------------------------------------------------------------
  // Set socket timeout
  //---------------------------------------------------------------------------
  err = socket_timeout_set(app_socket_fd,SOCK_STREAM);
  if (err) {
    d_printf(LINE_INFO,kDbg_Info|kDbg_General,&amp;quot;SetSockTimeoutErr:%d&amp;quot;, errno);
    return err;
  }
  //---------------------------------------------------------------------------
  // Connect
  //---------------------------------------------------------------------------
  err = blocking_connect(app_socket_fd, (struct sockaddr *)&amp;amp;local_addr,sizeof(struct sockaddr_in));
  if (errno &amp;amp;&amp;amp; err&amp;lt;0){
    err = errno;
    d_printf(LINE_INFO,kDbg_Info|kDbg_General,&amp;quot;ConnectionErr:%d %s&amp;quot;,errno,sIPPort);
  }else
    d_printf(LINE_INFO,kDbg_Info|kDbg_General,&amp;quot;Connected:%s&amp;quot;,sIPPort);
  return err;
} // connect_to_cloud
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connect errno -116</title><link>https://devzone.nordicsemi.com/thread/316061?ContentTypeID=1</link><pubDate>Fri, 18 Jun 2021 11:54:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:211f7f63-ad83-4bbf-8a0e-07945a00a839</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;have you checked the server side for any issues? Have you made sure that the connection isn&amp;#39;t being rejected by the server?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connect errno -116</title><link>https://devzone.nordicsemi.com/thread/315736?ContentTypeID=1</link><pubDate>Thu, 17 Jun 2021 04:46:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6470f1d-f78a-497a-bb52-6e796d5d8340</guid><dc:creator>DavidKaplan</dc:creator><description>&lt;p&gt;Shalom!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I had another bug opened and I posted this morning&amp;#39;s testing there by mistake so please see that thread with debug information.&lt;/p&gt;
&lt;p&gt;I am very sorry about the mixup, David&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/76060/lte-m-always-connected/314587#314587"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/76060/lte-m-always-connected/314587#314587&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connect errno -116</title><link>https://devzone.nordicsemi.com/thread/315609?ContentTypeID=1</link><pubDate>Wed, 16 Jun 2021 12:40:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e959889-9e7f-4c10-b353-2d67c3176a9f</guid><dc:creator>DavidKaplan</dc:creator><description>&lt;p&gt;Shalom!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I am now testing my re-connection algorithm in case that our TCP server is restarted or the network does down and etc.&lt;/p&gt;
&lt;p&gt;The same thing happens when I try to reconnect to the same IP.&lt;/p&gt;
&lt;p&gt;It must be something that I forgot to do.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;6-16 15:36 16/06/2021 12:36:48 |&amp;nbsp; 16/06/2021 15:37:06[ami_socket.c: 342] SocketFD:1&lt;br /&gt;6-16 15:36 16/06/2021 12:36:48 |&amp;nbsp; 16/06/2021 15:37:06[ami_socket.c: 286] SocketTimeout:30s&lt;br /&gt;6-16 15:36 16/06/2021 12:36:48 |&amp;nbsp; 16/06/2021 15:37:06[ami_main.c: 359] RRC mode:Connected&lt;br /&gt;6-16 15:36 16/06/2021 12:36:48 |&amp;nbsp; 16/06/2021 15:37:06[ami_socket.c: 357] ConnectionErr:116 192.117.103.217:8808&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>