I want to store a couple of sockets in an ArrayList/NSMutableArray, but the sockets are of type int and NSMutableArray only accepts objects (id). Is there another data type that I can use as a container for sockets? I am not sure how many entries I will have, so I would like the data container to be like an ArrayList.
Thanks!
EDIT: I’ve tried to send the socket as an NSNumber, but it did not work and caused XCode to crash when I tried to send a message using the socket.
You should wrap up your file descriptors in
NSFileHandleinstances, these will play nice inside collection objects such asNSArrayand are designed to wrap around file descriptors such as sockets. They also allow you to use standard Foundation types such asNSDatain conjunction with your communication.Note that
NSFileHandlealso provides convenience methods for accepting connections asynchronously, as well as asynchronous I/O. You can get the original file descriptor back by using thefileDescriptormethod.