Alexandre Kremer

[MCF52235] - TCP Client - Connect/Disconnect multiple times problem

Discussion created by Alexandre Kremer on Jul 3, 2008
Latest reply on Apr 10, 2012 by Umesh Bhagvatkar

I´m developing a product that needs to run a tcp client.
Basically, this product will connect to TCP Servers (one at a time), and retrieve data from it by sending a command and receiving the data.
The code for the client is working with no problems for a single Server. I mean, it connects to a server, sends the command and receives the data, and does this loop with no problems at all.
But when i add more than one server, the problem starts to happen. Basically, it connects to the first server, sends the command and receives the data. Then it must disconnect from the current server and connect to the second server to do the same task. After finishing the last server, it must connect to the first server and repeats this process.
The problem is that, after disconnecting from the first server by calling m_close function, it connects to the second, then to the third and so on, but one time it fails and nothing happens anymore, basically because the memory is full. So i can see the m_connect function returns ENOMEM (error 18), wich means it could not allocate memory for the new control block.
When i make the socket non-blocking, this get worst, and sometimes it just can´t pass the second server.

Please, any advice is helpfull.
I´m based on the Interniche stack and coldfire lite project.