-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error [ERR_SOCKET_DGRAM_IS_CONNECTED]: Already connected #3702
Comments
What i trying to do is a reconnect loop |
But if i try to send a packet it thow an error, |
@xxAROX I'm not sure exactly what you're trying to do, but if it helps, this code works: const dgram = require('dgram');
const web_socket = dgram.createSocket("udp4");
web_socket.on("connect", async (err) => {
console.log("Connected to socket");
web_socket.disconnect();
setTimeout(() => reconnectToSocket(), 1000 * 10);
});
const connectToSocket = (address, port) => {
web_socket.last_address = address;
web_socket.last_port = port;
if (!web_socket.connected) {
web_socket.connect(port ?? 16, address ?? "localhost");
}
}
const reconnectToSocket = () => {
console.log("RECONNECTING");
try {
web_socket.connect(web_socket.last_port ?? 16, web_socket.last_address ?? "localhost");
} catch (e) {
console.error(e);
}
}
connectToSocket(); I think there's some confusion about what client.send(message, 41234, 'localhost', (err) => {
client.close();
}); The documentation could probably be improved. @marsonya is looking into doing that. |
ahh okay thank you, that works |
|
ahh, i got this |
but first message was received from server |
I'm sorry. I don't understand what you're asking. Perhaps you can provide some code and explain what's not working the way you expect? |
This comment was marked as resolved.
This comment was marked as resolved.
ahh nvm, my issue |
Details
My client will not reconnect
Node.js version
v16.13.0
Example code
Operating system
win 10
Scope
code
Module and version
dgram
Result
The text was updated successfully, but these errors were encountered: