Comments (7)
Indeed changing the TCP connect timeout is not easy, especially considering the many platforms to support. But it is something I would like to implement in the future if possible, so I'll keep the issue open for now.
from kmqtt.
@davidepianca98 I've taken some time to work on that and I found a way... And it wasn't so difficult.
in the ClientSocket.kt (in jvmMain) this little change make the job:
public actual class ClientSocket actual constructor(
address: String,
port: Int,
maximumPacketSize: Int,
private val readTimeOut: Int,
checkCallback: () -> Unit
) : Socket(
SocketChannel.open(), //delay the connection by ignoring the connect information in the constructor
null,
ByteBuffer.allocate(maximumPacketSize),
ByteBuffer.allocate(maximumPacketSize)
) {
private val selector = Selector.open()
init {
channel.socket().connect(InetSocketAddress(address, port), 5000) //connect with a timeout parameter (nedd to be moved to the constructor parameters
channel.configureBlocking(false)
channel.register(selector, SelectionKey.OP_READ)
//handle the timeout with an exception
if (!channel.isConnected()) {
throw Exception("Custom Timeout")
}
}
This is a POC implementation but I hope it will help you in your work.
Cheers
from kmqtt.
Hello, thank you for the suggestion! Do you mean the TCP connection timeout or MQTT CONNACK response timeout?
The former is platform specific and probably a bit harder. The latter is very simple. I would like to add both but I am not able to give a timeline.
from kmqtt.
The CONNACK received timeout has been added here c97c4f9
from kmqtt.
Thanks that's great and quick!
In fact I was thinking of the TCP timeout.
My use case is:
- Client start and try to connect before the Broker is live and I would like to change the timeout so I can retry to connect.
When trying this test I found a consistent timeout of 130 seconds. I'll let you know here if I've found a way to deal with this.
--
edit: The connection timeout came from SocketChannel.open(InetSocketAddress(address, port)) and from what I've seen so far it's not that easy to change the timeout.
Anyway thank for your help!
from kmqtt.
Thanks a lot! I will definitely use this when I get to implement this. Now only the POSIX and JS implementation are needed.
from kmqtt.
Yes, sure, good luck on that ;)
from kmqtt.
Related Issues (20)
- Artifact publication on Maven Central? HOT 3
- iOSBuild failed with Could not find 'openssl-its-simulator-arm64' HOT 2
- ssl server certificate not found (IOS only) HOT 4
- Connecting to a home broker with TCP_PORT & MQTT_PORT HOT 4
- Source and JavaDoc missing from JVM artifacts HOT 1
- Error in recv: 9 on disconnect() HOT 12
- java.nio.BufferOverflowException when calling HOT 6
- Is it possible to add a path in MqttClient? HOT 2
- Provide the Client ID inside MQTTDisconnect HOT 2
- Expose the list of the connected client IDs HOT 5
- Delay in receiving published messages HOT 5
- TLSClientSettings from String instead of file path HOT 6
- Socket connection error on windows native HOT 1
- Delay in Publishing message HOT 2
- Can the broker host address be changed HOT 3
- Feature request: Use cklib to package openssl klibs HOT 1
- kmqtt-broker - Error on TLS javax.net.ssl.SSLException : Unable to parse TLS packet header HOT 4
- Ability to subscribe after broker connected HOT 2
- Any way to know if the broker has been started or stopped in the MQTT broker? Something like a listener ?? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kmqtt.