0

I am trying to make an iOS apps which connects to a C# server (using TCP) programmed similarly to that shown here. On the client (iOS) side, I use CFStreams and the CFStreamCreatePairWithSocketToHost method to connect to my cloud server. I have followed the tutorial found here precisely for the iOS side. A copy of the main connection program can be found here.

Unfortunately, when I run the app, I never get a NSStreamEventHasBytesAvailable event from the inputStream, even though the server is programmed to send a message to the client immediately after the connection has been made. Can someone help me fix this?

All help is greatly appreciated, and I always accept at least one answer!

danielmhanover
  • 3,094
  • 4
  • 35
  • 51
  • Have you followed this in your IOS app? The string from the client must contain the string "" to signal the end of the message. – James Black May 19 '12 at 01:11
  • Yes, I did that. Maybe its an encoding issue, though (I use NSASCIIStringEncoding on the iOS side)? – danielmhanover May 19 '12 at 01:12
  • You may want to print out on the server side what was received and what was sent. And you may want to read this, as he does a good job of giving ideas of how to get more info: http://stackoverflow.com/questions/10378001/byteswritten-but-other-device-never-receives-nsstreameventhasbytesavailable-eve – James Black May 19 '12 at 02:11
  • Server seems to be receiving and sending the messages as it should. Something must be wrong either on the iOS side, or with the TCP packet sent by the server. – danielmhanover May 19 '12 at 05:13
  • I just figured it out. A rather silly mistake on my part: I was accidentally releasing a string from memory, the one which as supposed to tell me if the connection was successful. As a result, I had though it'd failed, even though it didn't. If you submit your comment above as an answer, I will accept it, since it ultimately helped me find this mistake – danielmhanover May 19 '12 at 05:50

1 Answers1

0

You may want to print out on the server side what was received and what was sent. And you may want to read this, as he does a good job of giving ideas of how to get more info:

bytesWritten, but other device never receives NSStreamEventHasBytesAvailable event

Community
  • 1
  • 1
James Black
  • 41,583
  • 10
  • 86
  • 166