怎么了?服务器响应消息的不同结果
What is the wrong? Different results of the server response message
我想知道,代码中有什么错误。
我想得到正确的结果。
但是现在,在服务器端发送奇怪的结果。
下面的link是参考。
https:// firebase.google.com/docs/cloud-messaging/server#choose
结果如下。
connect ready
host: fcm-xmpp.googleapis.com, and port: 5236
connect ok
connect!
msg: <stream:stream
to="gcm.googleapis.com"version="1.0"xmlns="jabber:
client"xmlns:stream="http://eth erx.jabber.org/streams">
channelConnected
e.getMessage(): BigEndianHeapChannelBuffer(ridx=0, widx=7, cap=7)
MessageDumpByte> - length:<7>
[0000] 15 03 01 00 02 02 46 ......F
messageReceived:
补充一下,贴出了我做的简单代码
public class client2
{
final String host = "fcm-xmpp.googleapis.com";
// final String host = "127.0.0.1";
final int port = 5236;
Channel channel = null;
public static void main(String[] args) throws Exception
{
client2 client = new client2();
client.init();
}
public void init()
{
ClientBootstrap bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory()
{
public ChannelPipeline getPipeline() throws Exception
{
return Channels.pipeline(new ClientHandler());
}
});
System.out.println("connect ready");
System.out.println("host: " + host + ", and port: " + port);
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host,
port));
channel = future.getChannel();
System.out.println("connect ok");
}
}
class ClientHandler extends SimpleChannelUpstreamHandler
{
private ChannelBuffer firstMessage;
private final AtomicLong transferredBytes = new AtomicLong();
public ClientHandler()
{
}
public long getTransferredBytes()
{
return transferredBytes.get();
}
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
{
System.out.println("connect!");
StringBuilder msg = new StringBuilder();
msg.append("<stream:stream to=").append("\"")
.append("gcm.googleapis.com").append("\"").append("version=")
.append("\"").append("1.0").append("\"").append("xmlns=")
.append("\"").append("jabber:client").append("\"")
.append("xmlns:stream=").append("\"")
.append("http://etherx.jabber.org/streams").append("\"")
.append(">");
System.out.println("msg: " + msg.toString());
firstMessage = ChannelBuffers.copiedBuffer(msg.toString(),
CharsetUtil.UTF_8);
e.getChannel().write(firstMessage);
}
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
{
System.out.println("e.getMessage(): " + e.getMessage());
transferredBytes.addAndGet(((ChannelBuffer) e.getMessage())
.readableBytes());
ChannelBuffer cb = (ChannelBuffer) e.getMessage();
byte[] message = cb.array();
try
{
String dump = Utility.MessageDumpByte(message);
System.out.println(dump);
System.out.println("messageReceived: "
+ new String(message, "UTF-8"));
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
}
我用的是jdk1.7,Netty版本3.X
并且参考了这篇文档制作的
你缺少的是你必须首先建立一个 TLS 连接(这在文档中解释得很清楚)。
您得到的回复是:
0x15 Alert
0x03 0x01 TLS version 1.0
0x00 0x02 Message Length
0x02 Fatal
0x46 Certificate unknown
所以,去研究如何使用netty的SSL处理程序吧。
我想知道,代码中有什么错误。
我想得到正确的结果。
但是现在,在服务器端发送奇怪的结果。
下面的link是参考。
https:// firebase.google.com/docs/cloud-messaging/server#choose
结果如下。
connect ready
host: fcm-xmpp.googleapis.com, and port: 5236
connect ok
connect!
msg: <stream:stream
to="gcm.googleapis.com"version="1.0"xmlns="jabber:
client"xmlns:stream="http://eth erx.jabber.org/streams">
channelConnected
e.getMessage(): BigEndianHeapChannelBuffer(ridx=0, widx=7, cap=7)
MessageDumpByte> - length:<7>
[0000] 15 03 01 00 02 02 46 ......F
messageReceived:
补充一下,贴出了我做的简单代码
public class client2
{
final String host = "fcm-xmpp.googleapis.com";
// final String host = "127.0.0.1";
final int port = 5236;
Channel channel = null;
public static void main(String[] args) throws Exception
{
client2 client = new client2();
client.init();
}
public void init()
{
ClientBootstrap bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory()
{
public ChannelPipeline getPipeline() throws Exception
{
return Channels.pipeline(new ClientHandler());
}
});
System.out.println("connect ready");
System.out.println("host: " + host + ", and port: " + port);
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host,
port));
channel = future.getChannel();
System.out.println("connect ok");
}
}
class ClientHandler extends SimpleChannelUpstreamHandler
{
private ChannelBuffer firstMessage;
private final AtomicLong transferredBytes = new AtomicLong();
public ClientHandler()
{
}
public long getTransferredBytes()
{
return transferredBytes.get();
}
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
{
System.out.println("connect!");
StringBuilder msg = new StringBuilder();
msg.append("<stream:stream to=").append("\"")
.append("gcm.googleapis.com").append("\"").append("version=")
.append("\"").append("1.0").append("\"").append("xmlns=")
.append("\"").append("jabber:client").append("\"")
.append("xmlns:stream=").append("\"")
.append("http://etherx.jabber.org/streams").append("\"")
.append(">");
System.out.println("msg: " + msg.toString());
firstMessage = ChannelBuffers.copiedBuffer(msg.toString(),
CharsetUtil.UTF_8);
e.getChannel().write(firstMessage);
}
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
{
System.out.println("e.getMessage(): " + e.getMessage());
transferredBytes.addAndGet(((ChannelBuffer) e.getMessage())
.readableBytes());
ChannelBuffer cb = (ChannelBuffer) e.getMessage();
byte[] message = cb.array();
try
{
String dump = Utility.MessageDumpByte(message);
System.out.println(dump);
System.out.println("messageReceived: "
+ new String(message, "UTF-8"));
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
}
我用的是jdk1.7,Netty版本3.X
并且参考了这篇文档制作的
你缺少的是你必须首先建立一个 TLS 连接(这在文档中解释得很清楚)。
您得到的回复是:
0x15 Alert
0x03 0x01 TLS version 1.0
0x00 0x02 Message Length
0x02 Fatal
0x46 Certificate unknown
所以,去研究如何使用netty的SSL处理程序吧。