ipv4 tcp socket not create in contiki - iot

I m new to contiki and try to connect client ip 127.0.0.1 and port 502 to tcp server which is listening on 502 port but it always shows hostname not found or connection time out error. i tried contiki/example/http-socket. I want to send cc1310 launchpad sensor data on ipv4 server. can any one help me?

Related

I can't get any data from my broker with mosquitto_sub over the internet

in localhost, my broker works great, but when I use broker IP on another device to connect over the internet that's not work,
Websocket is fine
I use this command to subscribe on topic and get the retained messages
mosquitto_sub -h *.*.*.* -p 1883 -t mrt_connections/#
in localhost and when I used VPN I get current information, but when I use broker IP to use with another device over the internet I can't get any data
this log when I used Ip over the internet
1673794013: New connection from ****.****.***.**** on port 1883.
1673794013: New client connected from ****.****.***.**** as auto-48259EF8-9CF7-9CF5-3C2C-20FA8265C33A (p2, c1, k60).
1673794013: No will message specified.
1673794013: Sending CONNACK to auto-48259EF8-9CF7-9CF5-3C2C-20FA8265C33A (0, 0)
1673794017: New connection from *.*.*.* on port 1883.
I guessed that maybe port 1883 is blocked by ISP but another broker with the same port working, I test many IP but the problem is still alive,
can anybody explain to me what is a problem
thanks
I used version 2.0.15
config file
allow_anonymous true
listener 1883 *.*.*.*
log_type all
log_dest topic
log_dest stdout
Finally, I found the problem, the port was blocked by ISP and now MQTT works fine on port 443

Mosquitto configuration not accepting listener containing IP address

I have Mosquitto running on a local server, and my aim is to have 3 listeners:
all local network clients to connect without TLS on port 1883 (port 1883 is closed by router to public)
External clients to connect using TLS on port 8883
External client to connect without TLS on port 8880
which using this config works fine;
# Local MQTT
listener 1883
# End Local MQTT
# Insecure MQTT
listener 8880
# End Insecure MQTT
# Secure MQTT
listener 8883
## This is standard and should always be this
cafile /etc/ssl/certs/DST_Root_CA_X3.pem
## These are from your installation of LE
certfile /home/pi/.node-red/certs/fullchain.pem
keyfile /home/pi/.node-red/certs/privkey.pem
## Force all clients in this listener to provide a valid certificate, change th$
require_certificate true
## Stop all unauthorised connections
allow_anonymous false
## Use password file
password_file /etc/mosquitto/passwordfile
and which results in healthy Mosquitto log entries;
1575720819: Opening ipv4 listen socket on port 1883.
1575720819: Opening ipv6 listen socket on port 1883.
1575720819: Opening ipv4 listen socket on port 8883.
1575720819: Opening ipv6 listen socket on port 8883.
1575720819: Opening ipv4 listen socket on port 8880.
1575720819: Opening ipv6 listen socket on port 8880.
1575720820: New connection from 140.238.70.128 on port 8880.
1575719390: New client connected from 140.238.70.128 as telegraf (c1, k60, u'raspPi').
BUT... I want to ensure that only the client at 140.238.70.128 is able to connect on port 8880 (TLS isn't an option) so I added the IP address to the config;
# Insecure MQTT
listener 8880 140.238.70.128
# End Insecure MQTT
but that causes Mosquitto to stop, and the log shows;
1575720699: Opening ipv4 listen socket on port 1883.
1575720699: Opening ipv6 listen socket on port 1883.
1575720699: Opening ipv4 listen socket on port 8883.
1575720699: Opening ipv6 listen socket on port 8883.
1575720699: Opening ipv4 listen socket on port 8880.
1575720699: Error: Cannot assign requested address
I would be grateful for any advice as to why this doesn't work, or an alternative solution.
Edit. I also tried restricting the listener to ipv4, but that gave exactly same result;
# Insecure MQTT
listener 8880 140.238.70.128
socket_domain ipv4
# End Insecure MQTT
The listen directive can only take a address that is local to the machine the broker is running on. This is used to bind a socket to that address on the required port.
You can not use it as a filter for a remote machine, in fact there is no way to configure a port to only accept connections from a specific IP address in mosquitto* (or any other broker that I am aware of).
The only way to achieve what you want to do is to use the machines firewall to drop any packets from other IP addresses addressed to that port. You can use iptables to do this. Something like
iptables -A INPUT -p tcp --dport 8880 ! -s 140.238.70.129 DROP
This should drop any TCP packet destined for port 8880 that is not from 140.238.70.129
While this will work it will only block ipv4 clients, so if your networks has a properly routed IPv6 setup you will need to block access with ip6tables as well (and block access to port 1883).
* you might be able to write a custom auth plugin to do this, but I'm not sure if you get the remote IP address in the details about the user connecting. Also I don't think you can bind authentication to just one listener.

Contiki IPv4 connection to 127.0.0.1 loop back address

I m new to contiki. I used cc2650 sensortag and now i m using cc1310 launchpad. i use beagebone as a edge router and one cc1310 launchpad as a slipradio. everything works fine. i can open Coap and web and also i can get sensors data on web and coap.
now, i want to send sensor data on our own ipv4 cloud using tcp socket. but, i cant create tcp socket to my cloud. Is it possible to create ipv4 tcp socket directly from node?
#g-oikonomou #adamdunkels #farcaller can anyone suggest me how to create ipv4 tcp socket to 127.0.0.1 ip address and 1502 port?

Mosquitto Error

I am using Mosquitto for my project.
I have installed mosquitto-1.4.8-install-win32.exe and also place the three binary in folder
1. pthreadVC2.dll
2. libeay32.dll
3. ssleay32.dll
And reinstalled the mosquitto after that Started the services for mosquitto broker I entered following commands in cmd
*C:\Users\ravindra-s>netstat -an
Active Connections
Proto Local Address Foreign Address State
...
TCP 0.0.0.0:912 0.0.0.0:0 LISTENING
TCP 0.0.0.0:1883 0.0.0.0:0 LISTENING
TCP 0.0.0.0:2701 0.0.0.0:0 LISTENING
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
...
TCP [::]:135 [::]:0 LISTENING
TCP [::]:445 [::]:0 LISTENING
TCP [::]:1883 [::]:0 LISTENING
TCP [::]:2701 [::]:0 LISTENING
...
C:\Users\ravindra-s>cd "c:\Program Files"
c:\Program Files>cd mosquitto
c:\Program Files\mosquitto>mosquitto -v
1455619440: mosquitto version 1.4.8 (build date 14/02/2016 15:33:31.09) starting
1455619440: Using default config.
1455619440: Opening ipv6 listen socket on port 1883.
1455619440: Error: Unknown error*
It doesn't show that "Opening ipv4 listen socket on port 1883." and shows error now.
Previously my system does not show this error. but Now it is showing and my application is not running properly.
Please tell me to resolve this issue.
Any Help appreciated .
Thanks and Regards,
Ravindra
Looks like you already have mosquitto broker running and it's failing to open the ports (beacause they are already open).
Those lines shows that the 1883 (mqtt port) is already open...
TCP 0.0.0.0:1883 0.0.0.0:0 LISTENING
TCP [::]:1883 [::]:0 LISTENING
It may be due to windows running services of mosquitto.
First Stop mosquitto from windows services list
1.Press the Windows+R keys to open the Run dialog, type services.msc, press Enter
2.Search for mosquitto broker service
3.Stop the service
Now enter cmd as usual c:\Program Files\mosquitto>mosquitto -v
This will Opening ipv6 listen socket on port 1883.
as below
1455619440: Using default config.
1455619440: Opening ipv6 listen socket on port 1883.
1455619440: Opening ipv6 listen socket on port 1883.
Hope this will help you.

Does the port change when a server accepts a TCP connection?

When a client connects to a server using TCP, a new socket is created for the TCP stream. Does the connection remain on the same port the connection was made or does it get changed to some other port?
The new socket is an application-level concept introduced because each established connection needs a unique file descriptor (also distinct from the listening file descriptor), which maps to, but isn't the same as, a TCP session. The session itself is identified by the combination of source and destination address and port. The source (client) port is usually chosen at random, while the destination (server) port is the listen port. No additional port is allocated.
The server use the same port to listen and accept new connection, and communicate to the remote client.
Let's me give you an example, (in linux system):
First, start a http server by python:
xiongyu#ubuntu:~$ sudo python -m SimpleHTTPServer 500
Serving HTTP on 0.0.0.0 port 500 ...
Second use nc command to connect to the http server, here we start two client by:
xiongyu#ubuntu:~$ nc 0.0.0.0 500
Use netstat to see the netstate of port 500:
xiongyu#ubuntu:~$ netstat -natp |grep ':500'
tcp 0 0 0.0.0.0:500 0.0.0.0:* LISTEN 54661/python
tcp 0 0 127.0.0.1:51586 127.0.0.1:500 ESTABLISHED 57078/nc
tcp 0 0 127.0.0.1:51584 127.0.0.1:500 ESTABLISHED 54542/nc
tcp 0 0 127.0.0.1:500 127.0.0.1:51586 ESTABLISHED -
tcp 0 0 127.0.0.1:500 127.0.0.1:51584 ESTABLISHED 54661/python
You can see, the http server use port 500 to LISTEN for the client, after a new client connected to the server, it still use the port 500 to communite with the client, but with a new file descriptor .
The socket associated with the new descriptor returned by accept on the server will use the same port on the server side of the connection as the original socket (assuming "normal" definitions where the client initiates the connection). The new socket will have a different client port number (the remote port from the server's point of view).

Resources