我发现并希望在我的应用程序中实现的 java.nio 非阻塞服务器存在问题:
所以这就是正在发生的事情:每隔一段时间,它就会起作用。它可以连接到服务器,进行简单的握手并准备好来回发送消息。但通常情况下,它甚至没有收到连接的消息。以下是握手的工作原理:
Server sends cipher for encryption
Server sends "connected" to test connection and encryption
Client sends username
Server sends acknowledgment
Client sends password
Server sends acknowledgement
Server sends login success if that's the case
Client sends acknowledgment of login
Server asks for uuid
Client provides uuid
Server says it's ready
Client says it's ready
The handshake is complete and message transfer can begin
加密提到的是使用 jasypt。
每次我尝试它时,它都适用于 Android 2.2、2.3 和 Mac OS X (Java 1.6)。它在高于 3.0 的 Android 版本的每个服务器生命周期(启动、运行、终止)中工作一次。我知道 Android 网络的方式发生了重大变化,但我唯一知道的是你不能在主线程上做网络(这不是,这是一个从服务产生的线程。)我已经确认tcpdump
服务器实际上正在发送连接的消息。
任何帮助都会很棒,奇怪的是它只在 Android 3+ 中中断。
感谢您提前提供任何帮助。
编辑:我没有说清楚握手失败的地方。客户端收到密码后失败。通过调试,我知道客户端也得到了连接的消息,因为它不是读取缓冲区中唯一的东西:
Cipher:
[0, 16, 102, 69, 106, 80, 101, 56, 77, 72, 118, 117, 77, 75, 85, 100, 57, 78,
Connected:
0, 32, 53, 106, 43, 69, 104, 122, 87, 100, 109, 67, 85, 90, 121, 65, 83, 57, 98, 65, 78, 73, 103, 103, 66, 55, 103, 54, 55, 106, 54, 108, 54, 53, ...(Rest of buffer is zeros)...]
和是消息长度(分别为 160,16
和0,32
32)。这是在 TwoByteMessageLength.java 中定义的。
此外,它可能不是加密失败,因为这会引发一个很大的EncryptionOperationNotPossibleException
异常。