JAVA NIO TCP SOCKET ÁÄÌìȺ·¢
ÒÔÇ°¶¼ÊÇÓÃÒ»°ãµÄsocket±à³Ì£¬ÓÃÏß³ÌÀ´¿ØÖÆ¡£×î½üͻȻÓÃnioÀ´×öЩ¶«Î÷¡£
nioµÄºÃ´¦ÎÒÀ´ËµÒ»Ï£ºµÚÒ»£¬¶Áд¶¼ÊÇ»ùÓÚ¿éµÄ£¬Ð§Âʸߡ£µÚ¶þ£¬Í¨¹ýÒýÈëselector,¼ò»¯ÁËÍøÂç±à³ÌÄ£ÐÍ£¬Òì²½·Ç×èÈû¡£
¼ÈÈ»ÓÐÕâô¶àºÃ´¦£¬ÄǾÍд¸öNIO TCPÍøÂçÁÄÌìÊÒÀ´Á·Á·ÊÖ°É¡£
ÒòΪûÓÐдgui£¬ÊÇ»ùÓÚ¿ØÖÆ̨µÄËùÒÔûд˽Á˵IJ¿·Ö£¬Ö»Ð´Á˹«¹²ÁÄÌìÊÒ¡££¨Æäʵ£¬¼ÈÈ»ÊÇ·þÎñÆ÷¶Ë¿ÉÒÔ·Ö·¢¸øËùÓÐÈË£¬·Ö·¢¸øÌض¨ÈËÒ²ÊǺÜÈÝÒ×ʵÏֵġ£
×¢Ò⣺ÕâÀïÖ»ÊÇΪÁËÁ·ÊÖ£¬ÁªÏµ·þÎñÆ÷¶Ë·Ö·¢ÏûÏ¢µ½¸÷¸ö¿Í»§¶Ë¡£TCP À´Ð´ÁÄÌìÊÒ£¬ÔÚÏÖʵÖÐÊDz»¿ÉÈ¡µÄ¡£IM¶¼ÊÇ»ùÓÚUDPÀ´Ð´µÄ¡£
ÏÈÉÏ´úÂë°É¡£
·þÎñÆ÷¶Ë´úÂë 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.logging.Level;
import java.util.logging.Logger;
/**
*
* @author kevin
*/
public class MySocketServer implements Runnable{
private boolean running;
private Selector selector;
String writeMsg;
StringBuffer sb=new StringBuffer();
SelectionKey ssckey;
public MySocketServer(){
running=true;
}
public void init(){
try {
selector = Selector.open();
ServerSocketChannel ssc = ServerSocketChannel.open();
&nbs
Ïà¹ØÎĵµ£º
package Pack;
import java.text.*;
import java.util.*;
import java.text.DecimalFormat;
import java.util.*;
public class Test {
/**
* @param args
*/
public static void main(String args[]) {
yuesef(50,3);
}
public static void yuesef(int n, int m) {
ArrayList<Integer ......
ÔËÓüÓÃܼ¼Êõ±£»¤JavaÔ´´úÂë
java
³ÌÐòµÄÔ´´úÂëºÜÈÝÒ×±»±ðÈË͵¿´¡£Ö»ÒªÓÐÒ»¸ö·´±àÒëÆ÷£¬ÈκÎÈ˶¼¿ÉÒÔ·ÖÎö±ðÈ˵ĴúÂë¡£±¾ÎÄÌÖÂÛÈçºÎÔÚ²»ÐÞ¸ÄÔÓгÌÐòµÄÇé
¿öÏ£¬Í¨¹ý
¼ÓÃÜ
¼¼Êõ±£»¤Ô´´ú
Âë¡£
¡¡¡¡Ò»¡¢ÎªÊ²Ã´Òª
¼ÓÃÜ
£¿
¡¡ ......
¹²ÏíÄÚ´æÔÚJavaÖÐʵÏÖºÍÓ¦ÓÃ
Õª×Ôhttp://zc4530.javaeye.com/blog/326186
1¡¢¹²ÏíÄÚ´æ¶ÔÓ¦Ó¦Óÿª·¢µÄÒâÒå
¶ÔÊìÖªUNIXϵͳӦÓÿª·¢µÄ³ÌÐòÔ±À´Ëµ£¬IPC£¨InterProcess Communication£©»úÖÆÊǷdz£ÊìϤµÄ£¬IPC»ù±¾°üÀ¨¹²ÏíÄÚ´æ¡¢ÐźŵƲÙ×÷¡¢ÏûÏ¢¶ÓÁС¢ÐźŴ¦ÀíµÈ²¿·Ö£¬ÊÇ¿ª·¢Ó¦ÓÃÖзdz£ÖØÒªµÄ±Ø²»¿ÉÉٵŤ¾ß¡£ÆäÖй²Ï ......
¾õµÃÁôÑÔºÜÓеÀÀí£¬ÎÄÕºÜÕÜÀí£¬Ò»²¢×ªÔØ ½¨Òé¶ÁÕß¿´ÔÎĵØÖ·
×÷Õߣº ÈîÒ»·å
ÈÕÆÚ£º 2008Äê12Ô 7ÈÕ
ÏÂÃæµÄÎÄÕÂÊÇMore Joel on SoftwareÒ»ÊéµÄµÚ8ƪ¡£
ÎÒ¾õµÃ·ÒëÄѶȺܴó£¬ÕûÕûÁ½¸ö¹¤×÷ÈÕ£¬Ã¿Ìì8СʱÒÔÉÏ£¬²ÅÒë³öÁË5000×Ö¡£³ýÁËJoel´óÁ¿Ê¹ÓÃÙµÓÁíÒ»¸öÔÒòÊÇÔÎÄÉæ¼°"±à³ÌÔÀí"£¬ºÃ¶à¶«Î÷ÎÒ¸ù±¾²»¶®¡£Ï£ ......
JAVAÁ¬½ÓÊý¾Ý¿â´óÈ«
1£®Oracle8/8i/9iÊý¾Ý¿â£¨thinģʽ£©
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:ts"; //tsΪÊý¾Ý¿âµÄSID
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,u ......