我正在尝试编写一个xmpp客户端来发送/接收来自gtalk的消息.
在我真正开始实现之前,我考虑开发一个原型,看看我是否能够通过gtalk获得消息.
我写了下面的代码,我现在卡在我应该在开始加密连接之前请求谷歌的部分.
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class XmppConnect {
static String initiate_conn="<?xml version=\"1.0\"?>\n\r\n";
static String start_tls="";
public static void main(String [] args)
{
try {
Socket connection = new Socket("talk.google.com", 5222);
DataInputStream input = new DataInputStream(connection.getInputStream());
BufferedReader d = new BufferedReader(new InputStreamReader(input));
OutputStream to_server = null;
String responseLine;
to_server = connection.getOutputStream();
to_server.write(initiate_conn.getBytes());
responseLine = d.readLine();
System.out.println("Server: " + responseLine);
to_server.write(start_tls.getBytes());
responseLine = d.readLine();
System.out.println("Server: " + responseLine);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我可以将以下内容发送给谷歌
作为回应,我期待以下内容
但我从服务器上得不到任何回报.
来自wireshark的屏幕截图如下所示.
请求你的帮助,请不要告诉我使用现有的xmpp库,因为我只是不想.
问候,
马努!
更新
找到了解决方案.工作代码如下:
现在适用的代码如下.
现在我将致力于TLS实现并回到这里,有任何疑问:)
标签:google-talk,java,xmpp
来源: https://codeday.me/bug/20190902/1791603.html