基本信息
源码名称:简单的TCPIP服务器端demo程序
源码大小:1.01M
文件格式:.rar
开发语言:Java
更新时间:2019-01-21
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
简单的TCPIP服务器端demo程序
简单的TCPIP服务器端demo程序
public void run() { String reccharBuf = new String(); byte[] receiveBuf = new byte[BUFSIZE]; SimpleDateFormat df=new SimpleDateFormat("yyyy/MM/dd/HH:mm:ss"); while (true) { //System.out.println("等待客户端连接。。。。" df.format(new Date())); Console.showInformation("等待客户连接...." df.format(new Date())); Socket clntSock=null; BufferedInputStream in=null;//声明BufferedInputStream局部变量 try { clntSock = server.accept(); clntSock.setSoTimeout(15000); SocketAddress clientAddress = clntSock.getRemoteSocketAddress(); //System.out.println("Handling client at" clientAddress "/" df.format(new Date())); Console.showInformation("正在处理来自" clientAddress "/" df.format(new Date())); in = new BufferedInputStream(clntSock.getInputStream(), 1024);//得到从客户端发送来的数据,放到in中 while ((in.read(receiveBuf)) != -1) { reccharBuf=bytesToHex(receiveBuf); getMsg(receiveBuf); Iterator it = receiveBuf.iterator();//迭代器 while (it.hasNext()) {//检查迭代器中是否还有数据 //System.out.println(it.next()); Console.showInformation(it.next().toString());//将得到的数据打印出来 } datalist.clear();//清空集合中的数据 } //Iterator it = datalist.iterator();//迭代器 //while (it.hasNext()) {//检查迭代器中是否还有数据 //System.out.println(it.next()); // Console.showInformation(it.next().toString()); //} if (datalist.isEmpty()) { //setInsertindicator(true); Console.showInformation("未收到数据"); //System.out.println("未收到数据"); } else{ //setInsertindicator(true); } } catch (IOException e) { //System.out.println("客户端数据读取异常"); Console.showInformation("客户端数据读取异常"); setInsertindicator(false); datalist.clear(); safeClose(in); safeClose(clntSock); e.printStackTrace(); }finally{ datalist.clear(); } } }