Socket.io解压缩
public static void sendMessage(SocketIOClient client,String message){DeflaterOutputStream gzip = null;Deflater deflater = null;if(client==null){return;}try{if(client.get("isBinary").equals("true")){deflater = new Deflater(5, true);ByteArrayOutputStream arrayOutputStream = tl.get();if(arrayOutputStream==null){arrayOutputStream = new ByteArrayOutputStream ();tl.set(arrayOutputStream);Logs.getinfoLogger().info("MsgThread ["+Thread.currentThread().getName()+"] init ByteArrayOutputStream");}arrayOutputStream.reset();gzip = new DeflaterOutputStream(arrayOutputStream, deflater, 1024);gzip.write(message.getBytes());gzip.close();byte[] bytes = arrayOutputStream.toByteArray();client.sendEvent("m", bytes);}else{client.sendEvent("m", message);}}catch(Exception e){try {if(gzip!=null){gzip.close();}} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}Logs.getinfoLogger().info("MessageUtil-send error:",e);}finally{if(deflater!=null){deflater.end();}}
}
/*** 解压后台返回的数据* @param bytes 后台返回的压缩后的数据* @return*/
private String decompress(byte[] bytes) {Inflater decompresser = new Inflater(true);ByteArrayInputStream bais = new ByteArrayInputStream(bytes);ByteArrayOutputStream baos = new ByteArrayOutputStream();InflaterInputStream iis = new InflaterInputStream(bais, decompresser);byte[] buf = new byte[1024];try {int count = iis.read(buf);while (count != -1) {baos.write(buf, 0, count);count = iis.read(buf);}return new String(baos.toByteArray());} catch (final Exception e) {e.printStackTrace();return null;} finally {try {iis.close();} catch (IOException e) {e.printStackTrace();}}
}
Socket.io解压缩相关推荐
- ios视频通话三方_iOS基于Socket.io即时通讯IM实现,WebRTC实现视频通话
Socket.io-FLSocketIM-iOS 基于Socket.io iOS即时通讯客户端 iOS IM Client based on Socket.io 实现功能 文本发送 图片发送(从相册选 ...
- phaser.min.js_如何使用Phaser 3,Express和Socket.IO构建多人纸牌游戏
phaser.min.js I'm a tabletop game developer, and am continually looking for ways to digitize game ex ...
- node mongoose_如何使用Express,Mongoose和Socket.io在Node.js中构建实时聊天应用程序
node mongoose by Arun Mathew Kurian 通过阿伦·马修·库里安(Arun Mathew Kurian) 如何使用Express,Mongoose和Socket.io在N ...
- dotnet调用node.js写的socket服务(websocket/socket/socket.io)
https://github.com/jstott/socketio4net/tree/develop socket.io服务端node.js,.里面有js写的客户端:http://socket.io ...
- vue.js+socket.io打造一个好玩的新闻社区
title: Socket.io+vue打造新闻社区 date: 2017-06-12 20:19:05 tags: [vue.js,javascript,socket.io] vue2.0 + so ...
- socket io与vue-cli的结合使用
关于在vue中使用websocket的简易例子 使用vue-cli生成一个vue模版 安装三个依赖: npm install -s socket.io npm install -s vue-socke ...
- 使用React、Node.js、MongoDB、Socket.IO开发一个角色投票应用的学习过程(一)
这几篇都是我原来首发在 segmentfault 上的地址:https://segmentfault.com/a/1190000005040834 突然想起来我这个博客冷落了好多年了,也该更新一下,呵 ...
- 用coffee和socket.io实现的01背包算法
先说说我为什么写这些吧 当程序猿太苦逼了,真的,时间久了,真没有搬砖的成就感高,好歹人家能盖栋楼(身材也能练得不错),咱们指不定哪天来个熊孩子把硬盘格了就啥也没了. 这学期明显没把心放在前端上.... ...
- socket.io实现在线群聊
我自己在用socket.io开发,对官方网站上的文档,进行简单的整理,然后自己写了一个简单的聊天程序.最最开始 先安装socket.io: npm install socket.io 利用Node的搭 ...
最新文章
- 一文看懂Modbus协议
- NGINX 进程通信机制
- mysql显错注入,SQL注入:显错注入
- 原来R语言还有这些不为人知的用处!
- azure linux 多磁盘 lvm,EVE-NG扩展磁盘空间(扩展LVM卷)
- java中如何调用属性_java – 如何从属性文件导入值并在注释中使用它?
- RHEL 8 - 安装 webconsole
- XCode 4.0 iOS SDK 4.3 iPhone证书破解 完全教程
- php常用设计模式和算法,常用算法、问答、设计模式
- 架构师成长之旅_第一篇:插件与框架是什么?
- 数据结构之排序算法Java实现(8)—— 线性排序之计数排序算法
- python while快速写法_从零开始学Python,带你手把手实战之一
- 基于Java的学生成绩管理系统
- js实现分页并请求ajax,js实现ajax分页完整实例
- U盘安装CentOS 7解决方案 (fat系统文件4g限制)
- Belief Propagation信念传播算法详解
- Java 获取文件的真实类型,修改后缀名也能识别出来
- Canonical Address
- 指标公式c语言源码下载,【通达信】九全指标-指标公式源码
- python程序运行时间的几种分析方法