简体   繁体   中英

TCP Client in IOS 5, parts of previous string remains NSStream

I am getting pretty frustrated, i have an tcp server running on my mac where i have a couple of devices hooked up to. I wanted to have my iphone connected to it so i can run som commands from my iphone directly to my mac @ home.

The tcp client for my iphone works pretty good except for one fault, it seems like it doesnt clear up the outputstream for each string i send. Here is an example of what i am having problems with

  1. I type in "Start my browser" on my iphone client and hit send
  2. The message pops up on my mac, everything ok so far
  3. I want to send another command from my iphone and type "B" and hit send
  4. The output on the iphone will then be "Btart my browser"
  5. It seems as it keeps the previous string in cache or something.

Does anyone have any sugestions? I would appreciate all help, if you need to see any of my code please post an message saying so and i will have it posted.

Without any code I can only guess, but this looks like a bug in your code that handles the string input. In case you are using a NSMutableString / NSMutableData to store your input, make sure you clear that input after accepting a command. It now looks like you just overwrite the beginning without actually erasing it first.

The source of the problem was that my server software not emptying the datastream. When I emptied the stream on the server side, it worked perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM