【发布时间】:2014-06-16 19:01:33
【问题描述】:
所以我的代码应该将浮点数发送到服务器并从中接收整数。但事实并非如此。显然flush方法有问题,数据似乎没有进入服务器。在我的代码中,socket.output()/input() 和 _output/_input 返回包装到 DataStreams 中的 CipherStreams 以建立连接。 safeInstance 方法建立连接并创建密码。客户端中的 OuputStream 和服务器中的 InputStream 包含一个 int(0) 和带有客户端十六进制版本公钥的 UTF 字符串。密钥是相同的。是否有一些解决方案在发送数据后不关闭流(或关闭后更新它的方法)?使用 AES 加密。
在客户端我们有
try {
UtilDHSocket socket = UtilDHSocket.safeInstance(0);
socket.output().writeFloat(1.0F);
socket.output().flush();
int answer = socket.input().readInt();
socket.input().close();
socket.output().close();
socket.close();
return answer == 200;
} catch(Exception ex) {
error(ex);
return false;
}
在服务器端也有类似的东西
try {
float clientVersion = _input.readFloat();
if(clientVersion == Main._version) {
_output.writeInt(200);
} else {
_output.writeInt(418);
}
_output.flush();
_input.close();
_output.close();
_client.close();
} catch(Exception ex) {
warning("Unable to process packet form ",this._client.getInetAddress().getHostAddress());
debug(ex);
}
【问题讨论】:
标签: java sockets encryption outputstream