我在使用,我发现,想在我的应用程序来实现的java.nio非阻塞服务器的问题:问题与Android中的java.nio 3+
因此,这里是什么发生: 每隔一段时间,它都会有效。它可以连接到服务器,做一次小小的握手并准备好来回消息。但更多的时候,它甚至没有获得连接的信息。以下是握手的工作方式:
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)每次尝试时使用。它在每个服务器生命周期(开始,运行,死亡)都在Android 3.0以上版本上运行一次。我知道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)...]
的0,16
和0,32
是消息长度(分别为16和32)。这是在TwoByteMessageLength.java中定义的。
此外,它可能不是加密失败,因为这会抛出一个很大的异常'EncryptionOperationNotPossibleException
异常。
如果您在Android客户端获得任何异常,握手中是否有任何地方描述它发生故障,并且您持有你的操作过程中有一个Android wakelock? –
Android方面没有抛出异常。我不持有唤醒锁,我编辑了关于握手失败的问题,因为我认为这可能会澄清。 –
有没有一些很好的理由让你不使用SSL? – EJP