iosxmppxmpp4r

How to get port number for iPhone Chatting Application


I am developing a chat application.

But Right now chatting is possible with only google because I know only google's port no.

xmppClient = [[XMPPClient alloc] init];
[xmppClient addDelegate:self];

// Replace me with the proper domain and port.
// The example below is setup for a typical google talk account.
[xmppClient setDomain:@"talk.google.com"];
[xmppClient setPort:5222];

You can see that, google has set 5222 as port number.

Same way I want to set port no for yahoo, windows messenger & other popular sites, How can I get all these?

(Is it something like that - "XMPP is specific for Google ones" ? ? )


Solution

  • 5222/tcp is the default port for XMPP, but your implementation may have a different one. To find out, you do a DNS SRV query for _xmpp-client._tcp.YOURDOMAIN, where you replace YOURDOMAIN with the domain you're trying to connect to. This will return 0+ records that have hostname/port combinations for how to connect. If you get 0 records back, assume port 5222.

    For example, I want to connect to the GoogleTalk server, and log in with the account foo@gmail.com. My client performs the lookup that can be simulated with dig on the command line like this:

    % dig +short -t SRV _xmpp-client._tcp.gmail.com.
    20 0 5222 talk1.l.google.com.
    20 0 5222 talk4.l.google.com.
    5 0 5222 talk.l.google.com.
    20 0 5222 talk3.l.google.com.
    20 0 5222 talk2.l.google.com.
    

    The result with the lowest priority number is 5 0 5222 talk.l.google.com., which means you open a TCP connection to talk.l.google.com on port 5222.

    To make SRV queries from code, check out this answer, which relies on DNSServiceQueryRecord.