socket数据压缩传输问题

jerryhuang10 jerryhuang10 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
客户端:
socket = new Socket(host,4000);

ZipOutputStream zipout = new ZipOutputStream(socket.getOutputStream());
zipout.putNextEntry(new ZipEntry("a.zip"));

DataOutputStream output = new DataOutputStream(zipout);
DataInputStream input = new DataInputStream(socket.getInputStream());

output.writeLong(10000);
long clientNumber = input.readLong();//1234
output.writeInt(222);


服务器端:
ServerSocket serversocket = new ServerSocket(4000);
Socket client = serversocket.accept();
ZipInputStream zipin = new ZipInputStream(client.getInputStream());
zipin.getNextEntry();

input = new DataInputStream(zipin);
output = new DataOutputStream(client.getOutputStream());

output.writeInt(1234);
long magicNumber = input.readLong();//10000
int intnumber = input.readInt();//222

请问像上面这样用socket压缩数据进行传输可以吗?
好像在readLong()和readInt()时碰到了问题,程序被Block了,
请教高手,怎么样在socket压缩数据时用DataInputStream()和DataOutputStream()?
...全文
评论 2
收藏 已收藏
分享
返回顶部
jerryhuang10
Java SE 62,620 成员 307,251 内容