Re: SmallSockets
Re: SmallSockets
- Subject: Re: SmallSockets
- From: Chris Vincent <email@hidden>
- Date: Sun, 27 Oct 2002 00:12:27 -0500
Alright, I FINALLY got it working! And in the end, it wasn't very hard
at all. And I ditched the BufferedSocket class. For those interested,
this is it:
- (void)threadCommunicate:(id)dummy {
NSAutoreleasePool *apool=[[NSAutoreleasePool alloc] init];
while ([connection isConnected]) {
if ([connection isReadable]) {
NSMutableData *message = [[NSMutableData alloc] init];
NSString *strMessage;
[connection read
Data:message];
strMessage = [[NSString alloc] initWith
Data:message
encoding:NSUTF8StringEncoding];
[owner receivedMessage:strMessage];
[message release];
[strMessage release];
}
}
[apool release];
}
"owner" is the class's delegate. I'm getting ready to replace all that
with notifications, however. I hope this helps anyone who needs it.
On Saturday, October 26, 2002, at 11:33 PM, Chris Vincent wrote:
>
Okay. I really need someone's help with SmallSockets. I'm using the
>
BufferedSocket class and am running a thread to grab data as it comes
>
in. That's where the problem lies. I can't seem to get the data
>
correctly. I've tried many many different ways of doing it. Sometimes
>
garbage characters come in after the regular ones, sometimes it's just
>
garbage characters and nothing else. I have no idea what's wrong. It
>
just seems like it should work, but it doesn't. Currently, I'm doing it
>
like this ("connection" being a BufferedSocket):
>
>
while(1) {
>
NSAutoreleasePool *apool=[[NSAutoreleasePool alloc] init];
>
NSMutableData *message = [NSMutableData alloc];
>
NSString *strMessage;
>
[message initWithData:[connection readData:[connection
>
bufferLength]]];
>
if(!message) break;
>
strMessage = [NSString stringWithUTF8String:[message
>
bytes]];
>
if(strMessage) {
>
[owner receivedMessage:strMessage];
>
}
>
[message release];
>
[apool release];
>
}
>
>
That's the looping part of the thread. Doesn't it just look like it
>
should work? But it doesn't. It just gives me a bunch of garbage.
>
I've looked for hours on the net looking for good examples, but I've
>
failed to find one that does it right. I would super appreciate any
>
help with this very frustrating little problem.
>
>
"Someone is sitting in the shade today
>
because someone else planted a tree a hundred years ago."
>
- Unknown
>
>
~ Dris ~
>
>
- Random Signature #14 -
>
_______________________________________________
>
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.
>
>
"Someone is sitting in the shade today
because someone else planted a tree a hundred years ago."
- Unknown
~ Dris ~
- Random Signature #14 -
_______________________________________________
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.
References: | |
| >SmallSockets (From: Chris Vincent <email@hidden>) |