soulfly / STUN-iOS

STUN protocol implementation for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

STUN protocol implementation for iOS

This is a Session Traversal Utilities for NAT (STUN) protocol implementation for iOS. Original specification: http://tools.ietf.org/html/rfc5389

How it works

  1. Import STUNClient and GCDAsyncUdpSocket classes:

    #import "GCDAsyncUdpSocket.h"
    #import "STUNClient.h"  
    
  2. Add STUNClientDelegate protocol to your class:

     @interface MyClass : NSObject <STUNClientDelegate>{
    
  3. Create instances of GCDAsyncUdpSocket and STUNClient classes. Perform method requestPublicIPandPortWithUDPSocket:delegate: and pass to it udp socket & delegate:

     GCDAsyncUdpSocket *udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
    
     STUNClient *stunClient = [[STUNClient alloc] init];
     [stunClient requestPublicIPandPortWithUDPSocket:udpSocket delegate:self];
    
  4. Catch result in delegate's method *-(void)didReceivePublicIPandPort:(NSDictionary ) data:

     -(void)didReceivePublicIPandPort:(NSDictionary *) data{
         NSLog(@"Public IP=%@, public Port=%@, NAT is Symmetric: %@", [data objectForKey:publicIPKey],
         [data objectForKey:publicPortKey], [data objectForKey:isNATTypeSymmetric]);
     }
    
  5. See in log:

     2012-09-20 15:55:31.160 STUN[19255:f803] Public IP=52.177.223.158, public Port=42483
    
  6. Start send Indication messages:

     [stunClient startSendIndicationMessage];
    
  7. Injoit!

License

It's compeletely free, use this lib without any problems.
Just would be great if you add info somewhere in your app about author: "STUN-iOS: Igor form QuickBlox", but it's not a requirement.

About

STUN protocol implementation for iOS


Languages

Language:Objective-C 100.0%