当前位置:  开发笔记 > 编程语言 > 正文

如何在java中连接到gtalk?

如何解决《如何在java中连接到gtalk?》经验,为你挑选了0个好方法。

我试图在java中编写一个小的XMPP gtalk客户端.我知道有很多库可以帮助你,但RFC很容易理解,我决定自己编写一个客户端.我知道gtalk服务器是talk.google.com:5222但是当我尝试这个小程序时,我得到了这个结果:

 HTTP/1.1 302 Found
Location: http://www.google.com/talk/
Content-Type: text/html
Content-Length: 151

302 Moved

302 Moved

The document has moved here.

我也尝试连接指定的位置,但它不起作用.这是我在java中的代码:

    package fr.grosdim.myjabber;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocketFactory;

/**
 * Hello world!
 * 
 */
public class App {
    public static void main(String[] args) {
        SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory
                .getDefault();
        try {


            Socket s = new Socket("talk.google.com", 5222);

            PrintWriter out = new PrintWriter(s.getOutputStream());
            out.println("");
            out
                    .println("");
            out.flush();

            BufferedReader reader = new BufferedReader(new InputStreamReader(s
                    .getInputStream()));

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

            }

            out.println("");
            s.close();

        } catch (SSLPeerUnverifiedException e) {
            System.out.println(" Erreur d'auth :" + e.getLocalizedMessage());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println(e.getLocalizedMessage());
        }

    }
}

我如何连接到gtalk服务器?

推荐阅读
k78283381
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有