EthernetClient - Closed socket with data to be read is cleared by client.connect() #249
Labels
topic: code
Related to content of the project itself
type: imperfection
Perceived defect in any part of project
Hello,
I have a program where I need to connect to multiple servers and want to handle requests asynchronously.
I've created a
NetworkRequest
class (See below) which is essentially a state machine with its ownEthernetClient
, responsible for handling a request and its response. I have aNetworkRequest
instance for each server which I need to connect to. (In this case, two)I call the
Update()
method of eachNetworkRequest
instance every frame.Right now the first of the servers doesn't exist so it's expected to fail to connect to that IP. My issue is that the connection attempt of the first
NetworkRequest
instance causes the secondEthernetClient
's received data buffer to be cleared before it gets read.Essentially: (Assume both
NetworkRequest
instances have outstanding requests and are therefore inState::SendingRequest
)max
)0
) and state is progressed toState::AwaitingResponse
max
) - During thisEthernet.socketBegin()
will try to use the first closed socket (Socket index 0) and appears to clear the receive buffer)My workaround for this is to do two separate
Update()
loops - The first updates anyNetworkRequest
instances which are in theState::AwaitingResponse
state and the second then updates anyNetworkRequest
instances which are in theState::SendingRequest
state.Am I missing something here? It would be nice if
Ethernet.socketBegin()
would rotate through the unused sockets, or even if we could reserve a specific socket index for anEthernetClient
instance.The text was updated successfully, but these errors were encountered: