package com.supcon.hcc.connector;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
public class HccConnector {
boolean flag;
Socket socket;
long lastTime = 0;
BufferedReader input;
BufferedWriter out;
int buffSize;
public HccConnector(Socket socket,int buffSize){
this.socket = socket;
this.buffSize = buffSize;
try {
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
lastTime = System.currentTimeMillis();
flag = true;
} catch (IOException e) {
e.printStackTrace();
}
}
public String getMSG(){
boolean ready = false;
char[] msg = new char[1024];
try {
ready = input.ready();
if(ready){
input.read(msg);
}
if(ready){
lastTime = System.currentTimeMillis();
}else{
if((System.currentTimeMillis() - lastTime) > 5000){
flag = false;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new String(msg);
}
public void sendMSG(String msg){
try {
out.write(msg);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
public void close(){
System.out.println("close");
try {
input.close();
out.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}finally{
input = null;
out = null;
socket = null;
}
}
public boolean getFlag(){
return flag;
}
}
socket连接池加消息队列源码
4星 · 超过85%的资源 需积分: 9 36 浏览量
2012-08-06
13:57:24
上传
评论 10
收藏 5KB 7Z 举报
dengrongjie
- 粉丝: 0
- 资源: 4
最新资源
- Linux常用命令大全.pdf
- 2023-04-06-项目笔记 - 第一百零五阶段 - 4.4.2.103全局变量的作用域-103 -2024.04.16
- 本教程旨在为读者提供MySQL的基础知识和操作指南,帮助大家快速入门并掌握MySQL的核心概念
- 2023-04-06-项目笔记 - 第一百零五阶段 - 4.4.2.103全局变量的作用域-103 -2024.04.16
- OpenStack镜像管理与制作.md
- 计算机组成原理-唐朔飞版课后习题答案
- SQL+语法参考手册(SQL)/数据类型+资料介绍过程
- 基于python+flask+mysql实现的豆瓣电影可视化系统+源代码+文档说明+数据库.zip
- 本教程将引导你从头开始学习Python,帮助你掌握Python的基础知识,为进一步学习和应用Python打下坚实的基础
- ASP.NET高校学生宿舍管理系统的设计与实现(源代码+论文).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页