openfire Android 安装与配置(二)

来源:互联网 发布:游民星空mac游戏 编辑:程序博客网 时间:2024/04/30 15:42

1.关于openfire for Android 的Demo已经有很多,我就不贴代码了,找不到就上github上搜索openfire Android .

需要注意的点:

   Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine's network interfaces and settings and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall.

大概意思就是开发机和模拟器之间还隔着一层防火墙,模拟器是看不到开发机的(很像NAT)。要让模拟器能正常收发数据,必须进行对模拟器设置端口重定向。并且在模拟器上如果要访问开发机需要使用10.0.2.2这个地址(virtualbox也是用这些地址)。
有两种方法可以设置重定向,利用模拟器的console,或者用adb。
1、利用模拟器的console
   telnet连接到console,启动的第一个模拟器的console端口是5554(后面启动的模拟器依次增加2,因为一个模拟器占用两个端口,5555是留给adb的,若后面又开了一个模拟器,那么console端口就是5556)。
   telnet 127.0.0.1 5554
   如果要增加一条重定向设置,采用如下命令
   redir add <protocol>:<host-port>:<guest-port>
   例如:redir add udp:5000:6000  这样所有在开发机上5000端口的udp通信都会被重定向到模拟器的6000端口上。
   添加成功后,我们可以用redir list命令来列出已经添加的映射端口,redir del可以惊醒删除。

2、利用adb命令
adb forward tcp:6100 tcp:7100
这样就将宿主机的6100端口映射到模拟器的7100端口上(将tcp改成udp,会一直提示绑定失败)

3.主机IP地址的配置问题:在每一个连接当中一般都会有这段代码:
 
private static int SERVER_PORT = 5222 ;private static String SERVER_HOST = "192.168.0.5" ;
ConnectionConfiguration connConfig = new ConnectionConfiguration(SERVER_HOST,SERVER_PORT);con = new XMPPConnection(connConfig);con.connect();

SERVER_HOST   =   服务器地址(若你在本机上安装open fire,就是你电脑的IP地址,可以通过cmd---->ipconfig查看)
SERVER_PORT   =  默认是 5222
如果是在本地测试,还要保证你电脑和你手机在同一个网络中,不然就可能会导致很多莫名其妙的登录失败。
         

0 0