I've a Mosquitto Broker with websockets on Ubuntu 16.04.1 LTS (VM)
I use it in my production environment for a few week. I publish maybe 150 messages per second on average and tens of clients as subscribers with no problem.
I encounter the problem that "no client is able to connect" to both standart port and websocket port, 1883 and 8080 respectively. I even can't make a telnet connection to these ports. When I re-start the broker the problem goes away.
This situation occurs a few times in a few days.
I redirected the stdErr to a log file to investigate what is going on.
First lines:
1481665066: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1481665066: Config loaded from mosquitto.conf.
1481665066: Opening websockets listen socket on port 8080.
1481665066: Opening ipv4 listen socket on port 1883.
1481665066: Opening ipv6 listen socket on port 1883.
1481665066: New connection from 31.169.71.66 on port 1883.
1481665066: New client connected from 31.169.71.66 as dev32 (c1, k60, u'dev32').
1481665066: New connection from 31.169.71.66 on port 1883.
1481665066: New client connected from 78.186.134.50 as web_1f0a626d-072d-4803-b675-81c7042b14ec_20161214013743096 (c0, k30, u'dev').
1481665066: New client connected from 31.169.71.66 as dev39 (c1, k60, u'dev39').
1481665066: New connection from 31.169.71.66 on port 1883.
1481665066: New client connected from 92.44.21.41 as web_c3ebd064-6382-402a-a691-e20adddb2d01_20161214013902450 (c0, k30, u'dev').
1481665066: New client connected from 78.189.76.246 as web_8faeed52-465b-46cc-b330-e9760ea0d214_20161214003740750 (c0, k30, u'dev').
1481665066: New client connected from 31.169.71.66 as dev34 (c1, k60, u'dev34').
1481665066: New client connected from 95.8.136.192 as web_null_20161214003743476 (c0, k30, u'dev').
Last lines (just before I re-start the mosquitto)
1481774805: Client web_aa990b69-8e5b-458a-8d64-0167e5e844b6_20161215014005790 has exceeded timeout, disconnecting.
1481774807: Socket error on client web_aa990b69-8e5b-458a-8d64-0167e5e844b6_20161215014005790, disconnecting.
1481774943: New connection from 63.143.42.242 on port 1883.
1481774943: Socket error on client <unknown>, disconnecting.
1481775243: New connection from 63.143.42.242 on port 1883.
1481775243: Socket error on client <unknown>, disconnecting.
1481775543: New connection from 63.143.42.242 on port 1883.
1481775543: Socket error on client <unknown>, disconnecting.
1481775733: New connection from 31.169.71.66 on port 1883.
1481775733: Client dev26 already connected, closing old connection.
1481775733: Client dev26 disconnected.
1481775733: New client connected from 31.169.71.66 as dev26 (c1, k60, u'dev26').
1481775843: New connection from 63.143.42.242 on port 1883.
1481775843: Socket error on client <unknown>, disconnecting.
1481775903: Client web_2e62e4b3-19e6-4386-8525-f2ba7b77d90a_20161214212838816 has exceeded timeout, disconnecting.
1481775905: Socket error on client web_2e62e4b3-19e6-4386-8525-f2ba7b77d90a_20161214212838816, disconnecting.
1481776143: New connection from 63.143.42.242 on port 1883.
1481776143: Socket error on client <unknown>, disconnecting.
1481776622: New connection from 63.143.42.242 on port 1883.
1481776622: Socket error on client <unknown>, disconnecting.
1481776623: New connection from 31.169.71.66 on port 1883.
1481776623: Client dev37 already connected, closing old connection.
1481776623: Client dev37 disconnected.
1481776623: New client connected from 31.169.71.66 as dev37 (c1, k60, u'dev37').
1481776921: New connection from 63.143.42.242 on port 1883.
1481776921: Socket error on client <unknown>, disconnecting.
1481777221: New connection from 63.143.42.242 on port 1883.
1481777221: Socket error on client <unknown>, disconnecting.
1481777457: New connection from 31.169.71.66 on port 1883.
1481777457: Client dev28 already connected, closing old connection.
1481777457: Client dev28 disconnected.
1481777457: New client connected from 31.169.71.66 as dev28 (c1, k60, u'dev28').
1481777521: New connection from 63.143.42.242 on port 1883.
1481777521: Socket error on client <unknown>, disconnecting.
1481777821: New connection from 63.143.42.242 on port 1883.
1481777821: Socket error on client <unknown>, disconnecting.
1481778045: New connection from 63.143.42.242 on port 1883.
1481778045: Socket error on client <unknown>, disconnecting.
1481778344: New connection from 63.143.42.242 on port 1883.
1481778344: Socket error on client <unknown>, disconnecting.
1481778650: New connection from 63.143.42.242 on port 1883.
1481778650: Socket error on client <unknown>, disconnecting.
1481778950: New connection from 63.143.42.242 on port 1883.
1481778950: Socket error on client <unknown>, disconnecting.
1481779250: New connection from 63.143.42.242 on port 1883.
1481779250: Socket error on client <unknown>, disconnecting.
1481779550: New connection from 63.143.42.242 on port 1883.
1481779550: Socket error on client <unknown>, disconnecting.
1481779850: New connection from 63.143.42.242 on port 1883.
1481779850: Socket error on client <unknown>, disconnecting.
Note: 63.143.42.242 is uptimerobot service IP, so it just connects and disconnects to check whether the port is listening or not.
I use PAHO on both my JS and Java client side.
Full Log File is here: https://codeshare.io/2B7rb5 (3.6MB)
What can be the reason? Is there any solution?
Related
I'm using JavaMailSender and Outlook SMTP server for sending emails in a SpringBoot project.
Mail config:
host=smtp-mail.outlook.com
port=587
mail.transport.protocol=smtp
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.debug=true
When testing locally, everything works fine - email is sent to port 587 (see below) and delivered to the user.
DEBUG SMTP: trying to connect to host "smtp-mail.outlook.com", port 587, isSSL false
DEBUG SMTP: connected to host "smtp-mail.outlook.com", port: 587
The problem: When testing on production (Heroku server), email is being sent to port 5104:
DEBUG SMTP: trying to connect to host "smtp-mail.outlook.com", port 5104, isSSL false
That eventually ends with timed out connection exception and email is never sent to the user.
java.net.ConnectException: Connection timed out (Connection timed out). Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp-mail.outlook.com, 5104; timeout -1;
Edit: I've also figured that it uses different port on every email send try:
DEBUG SMTP: trying to connect to host "smtp-mail.outlook.com", port 58079, isSSL false
What is the reason for this behaviour? Why is it not using given port?
I'm using gorilla websocket and have problems with connection.
It works perfectly with wifi connection, but with cellular data (3G, 4G) it is not connection with following error:
read tcp myWhiteIp:2206->clientIp: read: connection reset by peer
Please HELP!
Mosquitto config:
per_listener_settings true
listener 1883
protocol mqtt
listener 9001
protocol websockets
require_certificate false
log_type all
allow_anonymous true
In Node-Red, I have an MQTT Publish node set to publish to localhost:1883.
When I run mosquitto without the listener 9001 and protocol websockets lines, node-red successfully connects and publishes to a topic. But I need websockets for a react application. When I run it with websockets on port 9001, I get the following error in mosquitto:
New connection from 127.0.0.1:61482 on port 1883.
Sending CONNACK to nodered_7b952a504a975460 (0, 5)
Client nodered_7b952a504a975460 disconnected, not authorised.
I've even tried using the websocket as the url for the node-red publish node like this:
ws://localhost:9001 and ws://localhost:9001/mqtt. Neither works.
What do I have to do to be able to publish from node-red to my react app via a local mosquitto broker?
I had to remove per_listener_settings true from the config file. I didn't realize I had it in there at first. Unfortunately, I do not know why this is the case.
I am trying to write something on WebSocket with Amazon ws. The problem is that I can not open the port by running this :
conn = new WebSocket('ws://ec2-54-213-181-25.us-west-2.compute.amazonaws.com:8081');
My port config on inbound and outbound in security for TCP and ICMP are all range 0-65535 and destination 0.0.0.0/0. But I still cannot open port 8081.
Can anyone tell me the wrong thing I did?
You have to create your websocket in private ip of Your EC2. Then you can connect your websocket using your public ip or url with port number
Pointed out that I need to open the port by this way :
socket = io.connect("abc:123");
so they are the same websocket version
I'm trying to implement TCP hole punching with windows socket using mingw toolchain. I think the process is right but the hole doesn't seems to take. I used this as reference.
A and B connect to the server S
S sends to A, B's router IP + the port it used to connect to S
S does the same for B
A start 2 threads:
One thread tries connecting to B's router with the info sent by S
The other thread is waiting for an incoming connection on the same port used to connect to its router when it connected to S
B does the same
I have no issue in the code I think since:
A and B does get each other ip and port to use
They are both listening on the port they used to connect to their router when they contacted the server
They are both connecting to the right ip and port but get timed out (code error 10060)
I am missing something ?
EDIT: With the help of process explorer, I see that one of the client managed to establish a connection to the peer. But the peer doesn't seems to consider the connection to be made.
Here is what I captured with Wireshark. For the sake of the example, the server S and the client A are on the same PC. The server S listens on a specific port (8060) redirected to that PC. B still tries to connect on the right IP because it sees that the public address of A sent by S is localhost and therefore uses the public IP of S instead. (I have replaced the public IPs by placeholders)
EDIT 2: I think the confusion is due to the fact that both incoming and outcoming connection request data are transfered on the same port. Which seems to mess up the connection state because we don't know which socket will get the data from the port. If I quote msdn:
The SO_REUSEADDR socket option allows a socket to forcibly bind to a
port in use by another socket. The second socket calls setsockopt with
the optname parameter set to SO_REUSEADDR and the optval parameter set
to a boolean value of TRUE before calling bind on the same port as the
original socket. Once the second socket has successfully bound, the
behavior for all sockets bound to that port is indeterminate.
But talking on the same port is required by the TCP Hole Punching technique to open up the holes !
A start 2 threads:
One thread tries connecting to B's router with the info sent by S
The other thread is waiting for an incoming connection on the same port used to connect to its router when it connected to S
You can't do this with two threads, since it's just one operation. Every TCP connection that is making an outbound connection is also waiting for an incoming connection. You simply call 'connect', and you are both sending outbound SYNs to make a connection and waiting for inbound SYNs to make a connection.
You may, however, need to close your connection to the server. Your platform likely doesn't permit you to make a TCP connection from a port when you already have an established connection from that same port. So just as you start TCP hole punching, close the connection to the server. Bind a new TCP socket to that same port, and call connect.
A simple solution to traverse into NAT routers is to make your traffic follow a protocol that your NAT already has an algorithm for forwarding, such as FTP.
Use Wireshark to check tcp connection request(3-way Handhsake process) is going properly.
Ensure your Listener thread is having select() to de-multiplex the descriptor.
sockPeerConect(socket used to connect Other peer) is FD_SET() in Listener Thread.
Ensure your are checking
int Listener Thread()
{
while(true)
{
FD_SET(sockPeerConn);
FD_SET(sockServerConn);
FD_SET(nConnectedSock );
if (FD_ISSET(sockPeerConect)
{
/// and calling accept() in side the
nConnectedSock = accept( ....);
}
if (FD_ISSET(sockServerConn)
{
/// receive data from Server
recv(sockServerConn );
}
if (FD_ISSET(nConnectedSock )
{
/// Receive data from Other Peer
recv(nConnectedSock );
}
}
}
5.Ensure you are simultaneously starting peer connection A to B and B to A.
6.Start your Listener Thread Prior to Connection to server and Peer and have Single Listener Thread for receiving Server and Client.
not every router supports tcp hole punching, please check out the following paper which explains in detail:
Peer-to-Peer Communication Across Network Address Translators