2014-11-08 31 views
0

我有一个vps,我想安装一个java服务器程序。它包含ssl,但我相信这不是用于java。至少它似乎没有真正加密。 奇怪的是,从ubuntu服务器发送2个字节得到补充,我没有指定,并且一些字节改变。我知道需要知道为什么它不这样做在Windows上,并在我的Ubuntu的vps ... 如果它是不同的如何解决它。是否java在ubuntu和windows上处理数据包的方式不同

我使用printWriter然后刷新到客户端。 和“ISO8859-1”来加密数据包,这些不是字符串或数字只是我发送的普通字节。

protected Socket socket; 
protected BufferedReader socketIn; 
protected PrintWriter socketOut; 
protected LoginServer server; 

public static final byte[] LOGIN_SUCCESSBYTE = {(byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00,   (byte)0x00, (byte)0x01, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00}; 

this.socketOut.write(new String(LoginServer.LOGINHEADER, "ISO8859-1")); 
this.socketOut.flush(); 
this.socketOut.write(new String(LoginServer.LOGIN_SUCCESSBYTE,"ISO8859-1")); 
this.socketOut.flush(); 

通过窗口 EC 2C发送4A 00 01 00 02 00 00 00 FF 00 00 00 00 00该分组。,J ..... ........
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ...... ..
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ......

ubuntu发送的数据包
00000000 C3 AC 2C 4A 00 01 00 02 00 00 00 C3 BF 00 00 00 ..,J .... ........
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .... .... ........
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........

+1

请给我们的代码。 – 2014-11-08 15:40:19

+0

请包含显示此行为的代码。 – 2014-11-08 15:48:08

回答

0

String不是二进制数据的容器,而Writer是用于字符数据,不是二元的。只需直接写入字节,使用OutputStream,而不是Writer。 Java根本不处理数据包,更不用说不同了,但它在不同平台上具有不同的默认字符编码。

+0

不是我希望找到的东西,因为我需要在代码中更改很多东西。大部分仍然固定。需要完成,所以如果我完成,所有的作品,我会标记这一个回答。 – jeroen 2014-11-09 20:52:16

相关问题