0

我尝试使用开源 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();
            }

    }

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

4

0 回答 0