destroying socket


I have a loop that close a socket if it is not equal to NULL and create the socket again. I can execute this loop 255 times. Why? How can I destroy the socket in order to avoid this problem?

Thanks in advance.
Who is Participating?
write; sysctl -A
and check fs.super-max
it should be 256 for your machine
increase it by issuing following command:
echo XXXX > /proc/sys/fs/super-max
where XXXX is the max number you want


Can you post the code for this?  From your description, the order of the loop sounds like:

if the socket is not NULL, close it.
create a new socket (socket is not null anymore).

jjescriAuthor Commented:
The loop is this

Begin Loop
  if the socket is not NULL, close it.
  create a new socket
End loop
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

your OS?
this is related to maximum file descriptors you can open at one time...
jjescriAuthor Commented:
My OS is Linux Red Hat 7.3
Can you elaborate on what it is you want your logic to do, and post some real code. It doesn't make much sense to continuously open and close your sockets (which is what you have said you are doing) without some other code in there to do something with them while they are open.  It would really help us to help you if you can tell us what the application needs to do, and show us what your current socket code looks like.  I don't think you will get any helpful comments otherwise (we can only guess what you are trying to do).

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.