I want to develop an iOS app which should be able to send messages to other WiFi direct enabled devices (no matter if it is an iOS device or Android device) and receive messages from them.
I found a suitable library ZeroMQ which can be used to accomplish the task. I have compiled the library for iOS successfully.
I reffered szehnder's sample code but the app doesn't do anything. It shows a blank table view only. I checked in the code and found that the code to receive a message is present there but the method to send the message is empty.
How can we detect other WiFi direct devices? Send and receive messages to them? Any pointers are highly appreciated.
As suggested by Jason, I am adding whatever I have achieved till now: I have an android app which connects to other android devices using WiFi direct and sends and receive messages from them, and uses ZeroMQ. I need to communicate with that app with my iOS app.
Below is my code to receive the messages:
-(void) setupSockets:(ZMQContext*)myContext {
ZMQSocket *subscriber = [myContext socketWithType:ZMQ_SUB];
[subscriber setData:nil forOption:ZMQ_SUBSCRIBE];
[subscriber connectToEndpoint: [NSString stringWithFormat:@"tcp://%@:%@", @"192.168.49.1", @"26665"]];
while (1) {
NSData *m = [subscriber receiveDataWithFlags:0];
if (m!=NULL) {
NSString *s = [NSString stringWithUTF8String:[m bytes]];
NSLog(@"Message: %@", s);
[self performSelectorOnMainThread:@selector(postMessageNotification:) withObject:s waitUntilDone:NO];
}
sleep(3);
}
}
Here 192.168.49.1 is the ip address of the host android device and 26665 is the port number used to receive messages. The control reaches up to call of receiveDataWithFlags: successfully but does nothing after that.
Now to send the data:
-(IBAction) sendMessageClicked:(id)sender {
NSString *pubEndPoint = [NSString stringWithFormat:@"tcp://%@:%@", @"192.168.49.1", @"26666"];
ZMQSocket *pubSocket = [objMeeps.context socketWithType:ZMQ_PUB];
[pubSocket connectToEndpoint:pubEndPoint];
NSData *msg = [@"hi" dataUsingEncoding:NSUTF8StringEncoding];
[pubSocket sendData:msg withFlags:ZMQ_NOBLOCK];
}
The method gives an error message ZMQLogError: *** <ZMQSocket: 0x17405fdd0 (ctx=0x174029480, type=ZMQ_PUB, endpoint=tcp://192.168.49.1:26666, closed=0)>: zmq_send: Resource temporarily unavailable
. When I searched regarding this error I got that the error is occurring due to absence of any receiver but my iPhone is connected to the WiFi network created by the android host using WiFi Direct.
I am new to ZeroMQ so might be missing something very small. Hope this clarifies the issue enough.Please guide me regarding this.