<?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>Cannot connect to the server over TCP (116 error)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110410/cannot-connect-to-the-server-over-tcp-116-error</link><description>Hi Nordic, 
 
 I am coding a program (TCP client) sending an array of bytes to a server over TCP. There is no error during the building process. And, there is also no error with modem initialization. But, I always receive the error 116 when I connect</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 22 Apr 2024 16:39:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110410/cannot-connect-to-the-server-over-tcp-116-error" /><item><title>RE: Cannot connect to the server over TCP (116 error)</title><link>https://devzone.nordicsemi.com/thread/480055?ContentTypeID=1</link><pubDate>Mon, 22 Apr 2024 16:39:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0185fdec-84be-4c6c-a247-002ec4352d25</guid><dc:creator>LuckyMan</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi &amp;Oslash;yvind,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;Thank you for your reply. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;That is quite weird, I do not know the reason. I programmed the board to work as a UDP client to send data to a UDP server that is run on an AWS server, and it works well. But, when I tried to program it to work as a TCP client to send data to a TCP server run on AWS, the connection failed. The problem is that I do not where I am wrong.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;- This is the log file: (&lt;/strong&gt;for safety reason, I delete the IP address in the log fine&lt;strong&gt; )&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting nRF Connect SDK v2.5.1 ***
Connecting
Modem initialization...
LTE cell changed: Cell ID: 103026701, Tracking area: 20100
RRC mode: Connected
Network registration status: Connected - home network
PSM parameter update: TAU: 3240, Active time: -1
RRC mode: Idle

RRC mode: Connected
Connect failed : 116
Closed the socket
Not able to initialize TCP server connection

IP address 2a05:d014:185:b700:b242....., Port number 7073

*********************************************
Data to send over LTE-M (as integers, with IMEI embedded as ASCII):
0       0       0       0       0       0       0       0       0       0       0       0       0       0  015      16      17      18      19      20      21      22      23      1
*********************************************
Failed to transmit TCP packet, 9 Bad file number
RRC mode: Idle&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;Everything is fine except error&amp;nbsp;&lt;strong&gt;116&amp;nbsp;&lt;/strong&gt;(see line 11 in the Log file &amp;quot;Connect failed : 116&amp;quot;), when I try to connect to the TCP server.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;- For the server&lt;/strong&gt;: It is just a simple TCP server that is run on AWS to test. I tested the TCP server code by using the Netcat tool, there is no problem with the TCP server code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;import time                                                  
import socket
import struct                                              
from ctypes import *                                         
import sys                                                 
from datetime import datetime                               
                     
import signal                                               
import os                                                   
import json                                                 
import logging                                              




logging.basicConfig(                                        
    filename=&amp;quot;TCP_RX_Log.log&amp;quot;,                                
    filemode=&amp;#39;a&amp;#39;,                                           
    format=&amp;#39;%(asctime)s %(levelname)-8s %(message)s&amp;#39;,       
    level=logging.INFO,                                     
    datefmt=&amp;#39;%Y-%m-%d %H:%M:%S&amp;#39;)                            

# Declare IP address + Port
localIP = &amp;quot;2a05:d014:185:b700...........................&amp;quot;          # IPv6 of AWS where we run UDP code on
recvPort = 7073                                             
buffersize = 4096                                                                               
host = &amp;#39;&amp;#39;                                                   

# Create a TCP/IP socket  
try:
    r = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)      
    r.bind((host, recvPort))                                    
    print (&amp;quot;Binding successful!&amp;quot;)
except:                                                         
    logging.critical(&amp;quot;Failed to bind port&amp;quot;)                     
    print(&amp;quot;Failed to bind the port&amp;quot;)
    sys.exit(1)


# In đường dẫn nơi chứa file Log (được tạo tr&amp;#234;n AWS)
logFile = os.getcwd() + &amp;quot;/TCP_RX_Log.log&amp;quot;                   
                                                            

#recvMsg, addr = r.recvfrom(buffersize)                     
def receiveMessage(connection, addr):                       
    # recvMsg, addr = r.recvfrom(buffersize)                
    recvMsg = connection.recv(buffersize)                    
    
    devIP = addr[0]                                                        
    devPort = addr[1]                                       
   
    try: 
        devIMEI = recvMsg[0:15].decode(encoding=&amp;#39;UTF-8&amp;#39;)    
    except:
        logging.error(&amp;quot;Couldn&amp;#39;t parse devIMEI&amp;quot;)
        devIMEI = 0
    
    return devIP, devPort, devIMEI, recvMsg                


if __name__ == &amp;quot;__main__&amp;quot;:
    logging.info(&amp;quot;TCP server Started!&amp;quot;)
    while 1:
        # Listen for incoming connections 
        r.listen()
        print (&amp;quot;waiting for a connection&amp;quot;)
        connection, addr = r.accept()                            
        if connection:                                                            
            print (f&amp;quot;Connected to client: {addr}&amp;quot;)
            devIP, devPort, devIMEI, recvMsg = receiveMessage(connection, addr)     
            if recvMsg:
                print (&amp;quot;Receive from client with IP: &amp;quot;, devIP, &amp;quot; and Port Number: &amp;quot;, devPort)
                print (&amp;quot;IMEI: &amp;quot;, devIMEI)

                for x in recvMsg:
                    print(&amp;quot;- &amp;quot;, (x))

                # Close the connection 
                connection.close()&lt;/pre&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your help!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;wu&lt;/span&gt;&lt;/p&gt;
&lt;div id="eJOY__extension_root" class="eJOY__extension_root_class"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot connect to the server over TCP (116 error)</title><link>https://devzone.nordicsemi.com/thread/479978?ContentTypeID=1</link><pubDate>Mon, 22 Apr 2024 12:05:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb5430c8-41df-4acd-ab7b-4b14d1485fed</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Difficult to tell. What server are you trying to connect? Could you please provide a modem trace and logs as well?&lt;/p&gt;
&lt;p&gt;Here is what I get:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting nRF Connect SDK v2.5.1 ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Image index: 0, Swap type: none
I: Bootloader chainload address offset: 0x10000
*** Booting nRF Connect SDK v2.5.1 ***
Connecting
Modem initialization...
LTE cell changed: Cell ID: 21627653, Tracking area: 33129
RRC mode: Connected
Network registration status: Connected - roaming

src PSM parameter update: TAU: 9000, Active time: -1
does not contain a character string representing a valid network address
Not able to initialize TCP server connection

IP address 2a05:d014:.............., Port number 7073

*********************************************
Data to send over LTE-M (as integers, with IMEI embedded as ASCII):
0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       15      16      17      18      1920      21      22      23      1
*********************************************
Failed to transmit TCP packet, 9 Bad file number
RRC mode: Idle&lt;/pre&gt;&lt;br /&gt;Thanks.&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>