Reading SmallSockets
Reading SmallSockets
- Subject: Reading SmallSockets
- From: Chris Vincent <email@hidden>
- Date: Sat, 26 Oct 2002 16:01:44 -0500
Right now I'm working with SmallSockets because I know it can do what I
need it to. However, I'm a little bit confused as to what's going on
when reading from the BufferedSocket class. I've looked at a couple of
sources, but none of them seem to get it exactly right. Here's what I
have in the communication thread (connection is a BufferedSocket):
- (void)threadCommunicate:(id)dummy {
NSAutoreleasePool *apool=[[NSAutoreleasePool alloc] init];
NSMutableData *message,*segment;
NSString *strMessage;
NS_DURING
while(1) {
NSAutoreleasePool *apool=[[NSAutoreleasePool alloc] init];
/*message = [connection readData:1];
[message append
Data:[connection read
Data:[connection
bufferLength]]];
if(!message) break;
strMessage = @"";
while([message length]) {
segment = [message getBytes:[message length]];
//[segment increaseLengthBy:1];
strMessage = [NSString stringWithUTF8String:[segment
bytes]];
}*/
message = [connection read
Data:[connection bufferLength]];
if(!message) break;
strMessage = [NSString stringWithUTF8String:[message bytes]];
if(strMessage) {
[owner receivedMessage:strMessage];
}
[apool release];
if(![connection isConnected]) [owner gotDisconnected];
}
NS_HANDLER
[owner gotDisconnected];
NS_ENDHANDLER
[apool release];
}
How did I come up with that? Again, a combination of sources that I've
looked at. My question is, what exactly is this doing? Shouldn't it
suffice to go "message = [connection read
Data:[connection
bufferLength]]"? As far as I know, that should return all the available
data. However, I tried, and it doesn't. And I have no clue how I would
handle exceptions such as failing to connect or being remotely
disconnected. If anyone could point me in the right direction on these
issues, I'd really appreciate it. Thanks!
____ ____ ____ ____
||D |||r |||i |||s ||
||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|
- Random Signature #11 -
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.