Closed ckurtz22 closed 1 year ago
That should be fine - the default constructor doesn't even bind() as client_ip_address is None. And even when you do specify a source IP address to choose the correct NIC we pass in 0 for the port to bind() which should tell the OS to choose any available source port in the ephemeral range. For UDP we use SO_REUSEADDR which may cause what you're seeing though you can just re-use the original client for things like discovery - you only need a new client for handling the TCP state.
I ended up resolving my issue by making a custom connector class for udsoncan where I could instantiate one connector for each ECU I wanted to communicate with and had the connector basically modify the specific_send() function to send that ECU's logical address. Then each connector used the same doipclient instance to communicate with the ECU through the gateway.
Not entirely certain what you are describing, but to describe the issue I had in more detail each instance of doipclient opened a new socket connection to the vehicle's gateway (which happens regardless of whether bind() is called). The gateway at least on the Polestar 2 would stop accepting TCP comms over the first socket after a second socket was connected.
I'm relatively noobish with networking stuff still, but my solution worked fine so I think I'll go ahead and close this now.
When I try to create a client for each of a few different ECUs I get an error because it creates multiple sockets on the same port but only the most recent socket remains usable.