socket 您的主机中的软件放弃了一个已建立的连接。

w5781665 2011-12-09 09:40:56


try {

boolean goon = true;
serverSocket = new ServerSocket(13000);

ThreadPoolExecutor threadPool = new ThreadPoolExecutor(100, // 线程池维护线程的最少数量
6000, // 线程池维护线程的最大数量
30, // 线程池维护线程所允许的空闲时间
TimeUnit.SECONDS, // 线程池维护线程所允许的空闲时间的单位
new ArrayBlockingQueue<Runnable>(5), // 线程池所使用的缓冲队列
new ThreadPoolExecutor.DiscardOldestPolicy()); // 线程池对拒绝任务的处理策略
while (goon) {
try {

Socket s = serverSocket.accept();
System.out.println("++++++++++++++++++++++++++++++服务器连接成功!");
s.setSoTimeout(0);
threadPool.submit(new com.royasoft.mas.web.shiyan.SendSms(s));

} catch (Exception e) {
e.printStackTrace();
}
}// end of while(goon)
} catch (Exception e) {
e.printStackTrace();
}













public class SendSms implements Runnable {

/*
* (non-Javadoc)
*
* @see java.lang.Runnable#run()
*/
private static final int BUFSIZE = 32;
String clientIp; // 客户端IP
Socket clientSock = null; // 客户端Socket
OutputStream out = null; // 客户端输出流
InputStream in = null; // 客户端输入流

public SendSms(Socket clientSock) {
this.clientSock = clientSock;
this.clientIp = clientSock.getInetAddress().getHostAddress();
}

public void run() {
try {
System.out.println("----进来------");
ReportMsgService reportMsgService = (ReportMsgService) ApplicationContextUtils
.getBean("reportMsgService");
PhoneMsgService phoneMsgService = (PhoneMsgService) ApplicationContextUtils
.getBean("phoneMsgService");
StationService stationService = (StationService) ApplicationContextUtils
.getBean("stationService");
MemberService memberService = (MemberService) ApplicationContextUtils
.getBean("memberService");
// os = clientSock.getOutputStream();
System.out.println("----准备获取输入流------");
// is = clientSock.getInputStream();
System.out.println("----获取输入流------");
int recvMsgSize;
byte[] receiveBuf = new byte[BUFSIZE];
clientSock.setSoTimeout(SmsConst.SMGP_SOCK_TIMEOUT); // 超时设置
//LotteryScoketServer.ip_pdu_map.put(clientIp, this); // 存入ip和线程对应表
// b,使用所返回的Socket实例的InputStream和OutputStream与客户端进行通信
in = clientSock.getInputStream();
InputStreamReader read = new InputStreamReader(
new BufferedInputStream(in));
out = clientSock.getOutputStream();
char[] cbuf = new char[100];
Arrays.fill(cbuf, '\0');
int len = read.read(cbuf, 0, 100);
StringBuilder sb = new StringBuilder(100);
sb.append(cbuf, 0, len);
System.out.println("报文+"+sb.toString());
System.out.println("--------结束---------");

} catch (Exception e) {
e.printStackTrace();

} finally {
try {
releaseMe();
Thread.sleep(1000);
} catch (Exception e) {
}
}
}



客户端是每一分钟发一次数据 我这边3分钟接一次 为什么?? 而且一开始不会断连 到后面客户端发3次 断一次
求高人 在线等 急
...全文
951 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧