Repository navigation
[NetLinkSocket Error 9] & [NetLinkSocket Error 8] #17
Description
Activity
The
socket.disconnect()method should still exist from v1 to v2 and largely function identically between the two versions. Nosocket.destroy()method exists, though disconnect is in abstract the same thing.In v1, if you called
disconnect(), thenconnect()it may have worked, however the underlying library powering this considers that undefined behavior and does not technically support socket re-use.So for V2 I moved the connect step into the constructor so there was no way via this JavaScript API to re-use the socket and encounter this undefined behavior.
Error 8 should be
ERROR_CONNECT_SOCKET, which should occur when the socket connection cannot be established, such as trying to connect to an address that is not listening. Error 9 should beERROR_SENDwhich commonly means a connection was lost after the initial connection. It's related to Error 10 which isERROR_READand should happen under the same circumstances except when you attempt to read the socket.I'm unsure why between the versions you'd encounter new errors. This JS module is just a thin wrapper over a C++ module, and I didn't really touch the underlying C++ logic between v1 to v2 to minimize runtime errors. I just cleaned up the API as outlined above, and exposed the UDP/TCP server functionality that NetLink Sockets already supported via this same thin API. Though if you have code examples I'd can take a look to help debug it.
My apologies, you are correct there is not a destroy method, i was getting confused by the error message thrown which states 'Cannot use NetlinkSocket that has already been destroyed' which i now get if i try to connect to a socket i had previously closed.
I moved around this problem by not closing the socket between commands, however now i am having the Error 8 & 9 further down the line so i suspect that it is the disconnect method which i now can not call which is giving me the problems.
Examples below
function commandOne() { // Create a new connection to the hardware const client = new SocketClientTCP(port, address, "IPv4"); for (let i = 0; i<array.length; i++) { let name = names[i]; if (name != 'xxx'){ let command1 = ("An example of a command to be sent"); client.send(command1); } else if (name === 'xxx'){ let command2 = ("A different command to be send"); client.send(command2); } client.receive(); client.disconnect(); } } }The user has the option to fire multiple different commands based on their requirements, so i want to close that connection after each function has executed in the case that the user only wants 1 command fired and then 6 hours latter decides to fire another, i don't want that connection is sit open for 6 hours and not be active.
Hi Jacob
I was a user of NetlinkWrapper v1 prior to the introduction of buffers and unit8 as sendable data.
I have updated my syntax to reflect the changes you made with V2 however now i get both Error 8 and Error 9 thrown throughout the code where when using with v1 i never had the issue.
I am wondering if my issue stems from the socket.disconnect() method from V1 being deprecated (my understanding of the new .destroy() method is that is kills the socket connection and makes it impossible to reestablish the connection, in comparison to .disconnect which allowed the user to reconnect) meaning now i have to keep the connection open at all times.
The unusual thing is the error throws in different places, so i could run clean and then have an error throw after the 3rd command, and then on the next run of exactly the same actions and data being passed the error is thrown in a completely different place.
Do you have any thoughts?