连接到java中的opensource xmpp库的nimbuzz聊天

时间:2013-09-27 06:40:35

标签: java xmpp nimbuzz

我尝试使用opensource xmpp库连接到nimbuzz聊天  我已经能够发现nimbuzz聊天协议是XMPP,我已经冒险尝试连接并与像agsXMPP这样的XMPP客户端库聊天。

到目前为止,我无法连接或执行任何操作,到目前为止我的代码看起来像是:

public static void main(String args[])
    {
            Socket s = null;
            try {
                s = new Socket("195.211.49.6", 5222);
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            PrintWriter out = null;
            try {
                out = new PrintWriter(s.getOutputStream());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            out.println("<stream:stream to='nimbuzz.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");

            out.flush();

            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new InputStreamReader(s
                        .getInputStream()));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    System.out.println(line);

                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            out.println("<iq type='set' xml:lang='en' id='terms' to='nimbuzz.com'><query xmlns='jabber:iq:auth'><username>myusername/username><password>mypassword</password><resource>Miranda</resource></query></iq>");
           out.flush();
            try {
                reader = new BufferedReader(new InputStreamReader(s
                        .getInputStream()));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                while ((line = reader.readLine()) != null) {
                    System.out.println(line);

                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                s.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

    }

但我没有连接。  任何人都有如何连接nimbuzz使用xmpp api发送消息或聊天?

0 个答案:

没有答案