Receiving UDP Packets
-
I’m using a BC95 Modem from uBlox. The SIM cards did not use the T-Cloud, instead I want to send and receive packets to our own UDP gateway in very raw format (no CDP or other stuff around).
The sending of packets from the modem to the gateway (listening on port 8472) works fine:
Received from xx.yy.zz.ww, Port 29541: Hello World!
I told the modem to listen at port 8472:
AT+NSOCR=DGRAM,17,8472,1
The registration seems to be ok. But sending back a UDP packet to the nbiot modem at xx.yy.zz.ww:8472 did not work.
The packet never arrives. From were did the NAT gateway ‘knows’, at which port the device is listening to?
-
You should firstly check your firewall rules. It’s possible that your server accepts incoming UDP packets but drops outgoing packets on that specific port. You should firstly check your firewall rules. If there is a problem on your servers side, I can try to explain to you how you can configure everything in python to get it to work. From this you can adapt it to your tools and infrastructure. First of all we open a socket and tell it to listen to a specific port:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((‘’, 16666)) # bind the socket to address (port)
message, address = sock.recvfrom(1024)
Now our server is ready to receive messages on port 16666. From our modem we send some data to the server with IP:Port in our case ww.xx.yy.zz:16666:at+nsost=0,ww.xx.yy.zz,16666,3,414243
In python you will then get something like thismessage = ‘ABC’
address = (‘85.147.106.108’, 3618)
With the following command we can send a message back to the client (our NB-IoT module):sock.sendto(“Hello World”, address)
With these commands everything should work properly.Make sure that you send the answer from the same socket (i.e. same source port) otherwise it won’t work (network will drop the packets). So for example the following won’t work:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((‘’, 16666)) # bind the socket to address (port)
message, address = sock.recvfrom(1024)
…
Receive some data here
…
sock.sendto(‘Hello World!’, address) # this will work fineNow we close the socket and open a new one with a different source port (on the same server so same IP)
sock.close()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((‘’, 1883)) # different source port than before
sock.sendto(‘Hello World!’, address)
Even so we send the packet to the correct address (IP:Port) the module will never receive the packet because the source port ist different this time.Please let me know if this was of any help.
Best regards