• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Efficiency in SmallSockets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Efficiency in SmallSockets
      • From: Paul Ferguson <email@hidden>
    • Re: Efficiency in SmallSockets
      • From: Marco Binder <email@hidden>
  • Prev by Date: Re: hiding an NSView?
  • Next by Date: Dynamic Menu Items
  • Previous by thread: Re: NSMatrix
  • Next by thread: Re: Efficiency in SmallSockets
  • Index(es):
    • Date
    • Thread