易截截图软件、单文件、免安装、纯绿色、仅160KB

技术贴:java nio的示例

package com.vista.Server;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
public class SelectorServer
{
private static int DEFAULT_SERVERPORT = 6018;//默认端口
private static int DEFAULT_BUFFERSIZE = 1024;//默认缓冲区大小为1024字节
private ServerSocketChannel channel;
private LinkedList<SocketChannel> clients;
private Selector readSelector;
private ByteBuffer buffer;//字节缓冲区
private int port;

public SelectorServer(int port) throws IOException
{
this.port = port;
this.clients = new LinkedList<SocketChannel>();
this.channel = null;
this.readSelector = Selector.open();//打开选择器
this.buffer = ByteBuffer.allocate(DEFAULT_BUFFERSIZE);
}
// 服务器程序在服务循环中调用sericeClients()方法为已接受的客户服务
public void serviceClients()throws IOException
{
Set keys;
Iterator it;
SelectionKey key;
SocketChannel client;
// 在readSelector上调用select()方法,参数1代表如果调用select的时候 那么阻塞最多1秒钟等待可用的客户端连接
if(readSelector.select(1) > 0)
{
keys = readSelector.selectedKeys(); // 取得代表端通道的键集合
it = keys.iterator();
// 遍历,为每一个客户服务
while(it.hasNext())
{
key = (SelectionKey)it.next();
if(key.isReadable())
{ // 如果通道可读,那么读此通道到buffer中
int bytes;
client = (SocketChannel)key.channel();// 取得键对应的通道
buffer.clear(); // 清空缓冲区中的内容,设置好positi


相关文档:

用java编写多线程ftp断点下载文件程序


作者
:
李志涛
邮箱地址
:lizhitao67116961@163.com
深圳优网科技有限公司
 
前几天看到有某位网友写了用http进行断点下载文件,但是网上没有看到ftp断点下载的文章或代码,现在本人写了一下。经过测试没有问题。请大家多多指教。如有疏漏的地方请各位技术友人指出。本人不胜感激。
 
package
test.d ......

用java编写多线程ftp断点下载文件程序

作者 : 李志涛
邮箱地址 :lizhitao67116961@163.com
深圳优网科技有限公司
 
前几天看到有某位网友写了用http进行断点下载文件,但是网上没有看到ftp断点下载的文章或代码,现在本人写了一下。经过测试没有问题。请大家多多指教。如有疏漏的地方请各位技术友人指出。本人不胜感激。
 
 
package t ......

java语句

java大致有3种语句:顺序语句、条件语句、循环语句
条件语句:
      第一种:if 条件
                      语句
      第二种:if 条件
 &nbs ......

Oracle + Sun: Java Strategy

Oracle and Sun
http://www.oracle.com/events/productstrategy/index.html
Oracle + Sun: Java Strategy
   http://oracle.com.edgesuite.net/ivt/4000/8104/9236/12630/lobby_external_flash_clean_480x360/default.htm 
Oracle + Sun: Java Strategy
  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号