Smack 라이브러리를 사용하여 XMPP 서버를 구현했지만 서버가 Google Cloud Messaging 서버 (현재는 Firebase)에서 메시지를 가져 오지만 문제는 GCM 서버에 안드로이드에서 하나의 메시지는, 내 XMPP 서버, (I 메시지자바의 XMPP 서버가 GCM 서버의 모든 메시지를 수신하지 못합니다.
<message id="gQaM0-6"><gcm xmlns="google:mobile:data">{"message_type":"ack","message_id":"0","to":"eVtypIWW7Q8:APA91bH5oU0AC3zyuCAWVYkMzoGQeIiGe71c2BL4lE5uFHRfB3iPXtD-qIJDmJZ3ySsPDi0VhkKl0Cz3XZG7rWa1Ca7pX9yQqzWSMXBiGK4SEO4Q-Owfr45E_VBJMrXqsSziuJhek"}</gcm></message>
가 있다고에만 알림을 볼 수 있지만 나는이 에 데이터가없는 경우에만 첫 번째 메시지를 수신하고 두 번째가 차단되고, 첫 번째 메시지 voidpipePacket (패킷 패킷) 여기 XMPP 서버의 전체 코드입니다 :
public class XMPPServer implements PacketListener {
private static XMPPServer sInstance = null;
private XMPPConnection connection;
private ConnectionConfiguration config;
private String mApiKey = null;
private String mProjectId = null;
private boolean mDebuggable = false;
private String fcmServerUsername = null;
public static XMPPServer getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You have to prepare the client first");
}
return sInstance;
}
public static XMPPServer prepareClient(String projectId, String apiKey, boolean debuggable) {
synchronized (XMPPServer.class) {
if (sInstance == null) {
sInstance = new XMPPServer(projectId, apiKey, debuggable);
}
}
return sInstance;
}
private XMPPServer(String projectId, String apiKey, boolean debuggable) {
this();
mApiKey = apiKey;
mProjectId = projectId;
mDebuggable = debuggable;
fcmServerUsername = mProjectId + "@" + Util.FCM_SERVER_CONNECTION;
}
private XMPPServer() {
// Add GcmPacketExtension
ProviderManager.getInstance().addExtensionProvider(Util.FCM_ELEMENT_NAME, Util.FCM_NAMESPACE,
new PacketExtensionProvider() {
@Override
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
String json = parser.nextText();
GcmPacketExtension packet = new GcmPacketExtension(json);
return packet;
}
});
}
/**
* Connects to FCM Cloud Connection Server using the supplied credentials
*/
public void connect() throws XMPPException {
config = new ConnectionConfiguration(Util.FCM_SERVER, Util.FCM_PORT);
config.setSecurityMode(SecurityMode.enabled);
config.setReconnectionAllowed(true);
config.setSocketFactory(SSLSocketFactory.getDefault());
// Launch a window with info about packets sent and received
config.setDebuggerEnabled(mDebuggable);
connection = new XMPPConnection(config);
connection.connect();
connection.addConnectionListener(new ConnectionListener() {
//a few overrided methods
});
// Handle incoming packets (the class implements the PacketListener)
connection.addPacketListener(this, new PacketTypeFilter(Message.class));
// Second message without data I get in this method (1)
connection.addPacketWriterInterceptor(new PacketInterceptor() {
@Override
public void interceptPacket(Packet packet) {
System.out.println("INTERCEPT PACKAGE: " + packet.toXML());
}
}, new PacketTypeFilter(Message.class));
connection.login(fcmServerUsername, mApiKey);
}
/**
* Normal message with my data I get in this method (2)
*/
@SuppressWarnings("unchecked")
@Override
public void processPacket(Packet packet) {
Message incomingMessage = (Message) packet;
GcmPacketExtension gcmPacket = (GcmPacketExtension) incomingMessage.getExtension(Util.FCM_NAMESPACE);
String json = gcmPacket.getJson();
System.out.println("Message : " + json);
}
(1)과 (2)로 표시된 가장 중요한 부분이 거의 있습니다. (빨리 찾기 위해 검색을 사용하십시오) 내 데이터로 첫 번째 메시지 만받을 수있는 이유는 무엇입니까? 왜 두 번째 메시지가 PacketInterceptor (mark (1))로 이동합니까? 앱 서버가 연결되어있는 경우
안녕하세요, 감사합니다! FCM_PORT = 5236을 사용하면 5235를 시도 할 것입니다. 아마도 상황이 바뀔 것입니다. – Dmitry