Can i connect between Android and IOS By WIFI-Direct? -
i want transfer file between android , ios wifi-direct
android have wifip2p library
and ios have multipear connectivity library wifi-direct
but not compatible between 2 libraries !!!
each other can't found network service
how connect between android , ios transfer file ????
you have use nsinputstream
& nsoutputstream
connect android. it's not simple task.
first,
@property (nonatomic, strong, readwrite) nsinputstream *inputstream; @property (nonatomic, strong, readwrite) nsoutputstream *outputstream;
then add method,
- (void)initnetworkcommunication { uint portno = 5555; cfreadstreamref readstream; cfwritestreamref writestream; cfstreamcreatepairwithsockettohost(null, (cfstringref)@"localhost", portno, &readstream, &writestream); inputstream = (__bridge nsinputstream *)readstream; outputstream = (__bridge nsoutputstream *)writestream; [inputstream setdelegate:self]; [outputstream setdelegate:self]; [inputstream scheduleinrunloop:[nsrunloop currentrunloop] formode:nsdefaultrunloopmode]; [outputstream scheduleinrunloop:[nsrunloop currentrunloop] formode:nsdefaultrunloopmode]; [inputstream open]; [outputstream open]; }
you have call method start stream.
and send stream, here example.
- (ibaction)photoclick:(id)sender { nsdata *newdata = uiimagepngrepresentation([uiimage imagenamed:@"s.jpg"]); int index = 0; int totallen = [newdata length]; uint8_t buffer[1024]; uint8_t *readbytes = (uint8_t *)[newdata bytes]; while (index < totallen) { if ([outputstream hasspaceavailable]) { nslog(@"sending"); int indexlen = (1024>(totallen-index))?(totallen-index):1024; (void)memcpy(buffer, readbytes, indexlen); int written = [outputstream write:buffer maxlength:indexlen]; if (written < 0) { break; } index += written; readbytes += written; } } }
Comments
Post a Comment