Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JAVA NIO TCP SOCKET ÁÄÌìȺ·¢(²¢·¢¶àÏß³ÌдÏûϢƪ)

·þÎñÆ÷ÖÐתÏûÏ¢£¬ÊÇ·ÑʱµÄÊ£¬¿ÉÒÔ¼ÓÈë¶àÏ̡߳£ÕâÑùÒÔÀ´£¬»á²úÉúºÜ¶àÏ̡߳£¿ÉÒÔÔËÓÃÏ̳߳ØÀ´¹ÜÀí¡£
ÕâÀïÔËÓÃjava.util.concurrent°üµÄExecutors.newCachedThreadPoolÀ´¹ÜÀí¡£
·Ï»°ÉÙ˵£¬ÉÏ´úÂ룺
·þÎñÆ÷¶Ë£ºMySocketServer.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kevin.nio;
import java.io.IOException;
import java.net.InetSocketAddress;
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.Date;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author kevin
 */
public class MySocketServer implements Runnable{
  
    private boolean running;
   
    private Selector selector;
    String writeMsg;
   
    SelectionKey ssckey;
    ExecutorService exec;
   
    public MySocketServer(){
       
        running=true;
        exec=Executors.newCachedThreadPool();
    }
   
    public void init(){
        try {
            selector = Selector.open();
            ServerSocketChannel ssc = ServerSocketChannel.open();
            ssc.configureBlocking(false);
            ssc.socket().bind(new InetSocketAddress(2345)


Ïà¹ØÎĵµ£º

´«ÖDz¥¿ÍjavaÅàѵ java»ù´¡Ö®JDBC

×òÌì˯µÃÌ«Íí£¬ÑÏÖØÓ°ÏìÁ˽ñÌìµÄѧϰ£¬ÊµÔÚÊǵò»³¥Ê§£¡
¹ØÓÚjavaµÄ»ù´¡ÖªÊ¶»¹ÓжþÊ®Ìì¾ÍÒª½áÊøÁË£¬ÏÖÔÚÎÒÃÇÒѾ­¿ªÊ¼×öһЩСµÄÁ·Ï°£¬·¢ÏÖ×Ô¼ºµÄ˼·ÓÐʱºò¸ú²»ÉÏ£¬
ÕæÉÏ»ð£¡
ѧ¶øÊµÏ°Ö®£¬²»ÄܶªÁËÎ÷¹Ï¼ñÖ¥Â飬ÉÏ¿ÎÒª½ô¸úÀÏʦ½Ú×࣬²»ÄÜ×Ô¼º×ö×Ô¼ºµÄ£¬ÀÏʦ½²ÀÏʦµÄ£¡
µ÷ÕûÐÄ̬£¬ÓúõÄѧϰ·½·¨·½ÄÜʰ빦±¶£»
JDBC£¨Ja ......

ʹÓÃEclipseÓëAnt½øÐÐjava³ÌÐò¿ª·¢

ÏàÐÅ´ó¼ÒÒѾ­¶ÔEclipseµÄʹÓÃÓÐÒ»¶¨µÄ¾­Ñé,ÔÚ±àдjavaÔ´´úÂëÊǼþÌý×ÔºÀµÄÊÂ,´óÒª±àÒëÒ»´óÅújavaÔ´´úÂëȴʵ¼ù±È½Ï¿àÄÕµÄÊÂÇé,Èç¹ûÒ»¸öÒ»¸öµã"run"È¥±àÒëʵÔÚÌ«ÀË·Ñʱ¼äÁË.ÏëÍÑÀë"¿àº£",ÏÖÔھ͸ú×ÅżÃÇÒ»Æë×ß°É,²½ÈëAntµÄʹÓÃÀú³Ì.
    1.°²×°Ant
    a.ʹÓÃEclipse.3.2°æ±¾×Ô´øµÄAnt¿ÉÒÔÊ¡È ......

JAVA·´Éä»úÖÆµÄ¼òµ¥Ó¦ÓÃ

  ¿ª·¢µÄʱºòÓÐʱºò»áÅöµ½ÕâÑùµÄÇé¿ö£¬ÎÒÃÇÔÚд³ÌÐòµÄʱºò²¢²»ÖªµÀÐèÒªµ÷ÓÃij¸ö¶ÔÏóµÄÄĸö·½·¨£¬Ö»ÓгÌÐòÔËÐкó£¬ÎÒÃDzÅÄܹ»ÖªµÀ¡£»òÐíÎÒÃÇÐèÒª¸ù¾Ý¿Í»§¶Ë´«¹ýÀ´µÄij¸öString²ÎÊýµÄÖµÀ´ÅжÏÎÒÃÇÓ¦¸ÃÖ´ÐÐÄĸö·½·¨¡£ÔÚÕâÖÖÇé¿öÏÂJAVAµÄ·´ÉäÖ´ÐоͿÉÒÔ°ïÉÏæÁË¡£ÏÂÃæÊÇÎÒ×öµÄÒ»¸ö¼òµ¥µÄ²âÊÔ´úÂ룬Ìṩ¸ø´ó¼Ò×ö¸ö²Î¿¼¡£
i ......

JavaÖеÄö¾ÙÀàÐÍ£¬enum

public class MyEnumTestMain {
public enum MyenumTest{red,blue,green,black}//¶¨Òåö¾ÙÀàÐÍ

public static void main(String[] args) {
MyenumTest mt = MyenumTest.red;//redÏ൱ÓÚö¾ÙµÄ¾²Ì¬ÊôÐÔ

switch(mt){
case red:
System.out.println("red");
break;
case blue:
......

ÓÃJavaʵÏÖ·Ç×èÈûͨÐÅ

ÓÃServerSocketºÍSocketÀ´±àд·þÎñÆ÷³ÌÐòºÍ¿Í»§³ÌÐò£¬ÊÇJavaÍøÂç±à³ÌµÄ×î»ù±¾µÄ·½Ê½¡£ÕâЩ·þÎñÆ÷³ÌÐò»ò¿Í»§³ÌÐòÔÚÔËÐйý³ÌÖг£³£»á×èÈû¡£ÀýÈçµ±Ò»¸öÏß³ÌÖ´ÐÐServerSocketµÄaccept()·½·¨Ê±£¬¼ÙÈçûÓпͻ§Á¬½Ó£¬¸ÃÏ߳̾ͻáÒ»Ö±µÈµ½ÓÐÁ˿ͻ§Á¬½Ó²Å´Óaccept()·½·¨·µ»Ø¡£ÔÙÀýÈçµ±Ïß³ÌÖ´ÐÐSocketµÄread()·½·¨Ê±£¬Èç¹ûÊäÈëÁ÷ÖÐûÓÐ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ