Efficiency in SmallSockets
Efficiency in SmallSockets
- Subject: Efficiency in SmallSockets
- From: Anthony Duer <email@hidden>
- Date: Mon, 16 Sep 2002 15:05:43 -0700
Hi, I'm having a trouble with efficiency in SmallSockets. My problem
occurs with a latency in when text arrives and the speed in which I can
process it. Currently I'm developing a text-based game client which
connects to a game server via a simple TCP/IP connection. My problem is
that when I go to read from the socket, I first have to put the data
from the socket into a NSData, read from the NSData into a NSString,
then insert the NSString into a NSTextView. Under heavy load (10-20
lines/second) this seems to become very bogged down, taking a few
seconds to 'catch up' to where the current status is. Here's my current
working code, the function is run on a seperate Thread:
while([mySocket isConnected])
{
if([mySocket isReadable])
{
[mySocket readData: myData];
while([myData containsString: @"\n"])
{
line = [[NSString alloc] initWithData: [myData
getBytesUpToString: @"\n"] encoding: NSUTF8StringEncoding];
[mainText setEditable: YES];
[mainText insertText: line];
[mainText setEditable: NO];
[line release];
[mainText moveToEndOfDocument:mainText];
[mainText scrollRangeToVisible:[mainText selectedRange]];
}
}
else
{
[NSThread sleepUntilDate:[NSDate
dateWithTimeIntervalSinceNow:0.05]];
}
}
~Anthony Duer
_______________________________________________
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.