Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

donfrench

macrumors newbie
Original poster
Jun 12, 2009
15
0
I am writing an app that uses WiFi for a 2-way communicate with a program running on a Mac. I started by modifying the WiTap example. But the problem I have is that, unlike WiTap, my app needs to immediately send a message when the stream is open and respond to incoming TCP messages by sending a reply message. In WiTap, once the NSStreamEventOpenCompleted event is sent to the stream event handler, it displays an alert and returns. But what I want to do at that point is to send my first message to the server. If I try to do it from inside the event handler, hasSpaceAvailable is always false and transmission is impossible. Furthermore, I need to send reply messages whenever I get an incoming message and the same problem exists if I try to reply before returning from the stream event handler.

So it seems like I need to just set a value in the stream event handler and then fire another event off of my own design and then test that value in my event handler. But new as I am to iPhone (or Mac) development, I don't know how to do fire events or write event handlers - or even if this is the correct approach. Or does the solution lie in using the run loop - also new to me?

Anyone?
 
I am writing an app that uses WiFi for a 2-way communicate with a program running on a Mac. I started by modifying the WiTap example. But the problem I have is that, unlike WiTap, my app needs to immediately send a message when the stream is open and respond to incoming TCP messages by sending a reply message. In WiTap, once the NSStreamEventOpenCompleted event is sent to the stream event handler, it displays an alert and returns. But what I want to do at that point is to send my first message to the server. If I try to do it from inside the event handler, hasSpaceAvailable is always false and transmission is impossible. Furthermore, I need to send reply messages whenever I get an incoming message and the same problem exists if I try to reply before returning from the stream event handler.

So it seems like I need to just set a value in the stream event handler and then fire another event off of my own design and then test that value in my event handler. But new as I am to iPhone (or Mac) development, I don't know how to do fire events or write event handlers - or even if this is the correct approach. Or does the solution lie in using the run loop - also new to me?

Anyone?

I was partially mistaken. It turns out that it is true that it is not possible to output to the stream when the event handler is responding to a NSStreamEventOpenCompleted event, it IS possible when responding to a NSStreamEventHasBytesAvailable event, so I only have the one problem of getting the conversation started.
 
WiFi, WiTap, and the stream event handler

Hi there,
I have a similar problem. Just wondering if you managed to resolve this?

Regds,
Max
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.