I don't know if I understand the problem correctly but...
If you know that you can open only 200 sockets then why don't you just keep a counter and increment/decrement it whenever you open/close sockets?
Or maybe even make it dynamic; i.e., keep opening sockets until you get an error and note how many sockets you had open at that time - this will be your maximum.