3

I am developing a chat application using XMPP framework. I can send and receive chat messages, and I want to transfer a file.

I used TURNSocket but it didn't work.

My code:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSMutableArray *turnSockets=[NSMutableArray alloc] init];
    }
    return self;
}

- (void)viewDidLoad
{
    XMPPJID *jid = [XMPPJID jidWithString:@"venkat.varra@gmail.com/gmail.9D2001A1"];
    TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:jid];
   [turnSockets addObject:turnSocket];
   [turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}

- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket 
{
    NSData *dataF = [[NSData alloc] initWithContentsOfFile:
    [[NSBundle mainBundle] pathForResource:@"orange" ofType:@"png"]];

    [socket writeData:dataF withTimeout:60.0f tag:0];
}

- (void)turnSocketDidFail:(TURNSocket *)sender 
{
    NSLog(@"TURN Connection failed!");
    [turnSockets removeObject:sender];          
}

When I run this program it always calles turnsocketDidFail method.

How can I achieve file transfers in a chat application using turn socket in iPhone? can any one help me? Thanks in advance

TommySM
  • 3,793
  • 3
  • 24
  • 36
venkat
  • 762
  • 2
  • 8
  • 20

1 Answers1

0

If you want to send a file then simply upload that file to your server using a web service and after the upload is complete, send the uploaded file URL to another user. That user can now easily download the file from that specific URL.

TommySM
  • 3,793
  • 3
  • 24
  • 36
Parthpatel1105
  • 541
  • 6
  • 17