JavaÍøÂç±à³Ì³õ²½
JavaÍøÂç±à³Ì³õ²½
Kagula
2009-11-23
¹Ø¼ü´Ê
Java Socket DataInputStream DataOutputStream
¸ÅÒª
ʹÓÃJavaͬ²½IOÓ¦ÓóÌÐò¿â£¬ÊµÏÖCS½á¹¹ÍøÂç±à³Ì¡£
ÕýÎÄ
ʹÓÃSocketÀ´½¨Á¢ÍøÂçÁ¬½Ó£¬Ê¹ÓÃDataInputStream¡¢DataOutputStreamÀ´´æÈ¡ÍøÂçÁ÷¡£
¿Í»§¶Ë²¿·Ý
µÚÒ»²½£º½¨Á¢ÍøÂçÁ¬½Ó¶ÔÏ󣬺ÍÍøÂçÁ÷ÊäÈëÊä³ö¶ÔÏó
Socket c = new Socket(InetAddress.getByName("192.168.0.144"),6009);
dis = new DataInputStream(c.getInputStream());
dos = new DataOutputStream(c.getOutputStream());
µÚ¶þ²½£º¶ÁдÍøÂçÁ÷
д×Ö·û´®ÓÃÏÂÃæµÄ´úÂë
dos.writeUTF(list.get(i).toString());
dos.flush();
д¶þ½øÖÆÊý¾Ý²ÉÓÃÏÂÃæµÄ´úÂë
//byte[] b = new byte[nnL];
dos.write(b,0,nnL);
dos.flush();
ÕâÀïҪעÒâµÄÊÇwriteº¯ÊýµÄµÚ¶þ¸ö²ÎÊý£¬Ö¸µÄÊÇ»º´æÇøÆðʼλÖã¬nnLÖ¸µÄÊÇ»º´æÇøÖÐÊý¾ÝµÄ³¤¶È¡£b»º´æµÄ´óС½¨ÒéΪ1KB£¬¹ý´ó»áµ¼Ö²¿·ÝÊý¾Ý·¢ËͳöÈ¥ÁË£¬µ«ÊǽÓÊÕµ½Ã»ÓÐÊÕµ½ÓÐЧµÄÊý¾Ý¡£
¶Á×Ö·û´®ÓÃÏÂÃæµÄ´úÂë
String sR = dis.readUTF();
¶Á¶þ½øÖÆÊý¾ÝÓÃÏÂÃæµÄ´úÂë
Dis.read(b,0,nnL);
ÕâÀïÐèҪעÒ⣬·¢ËͶËͬ½ÓÊÕ¶ËÖ®¼ä£¬ÍøÂçÁ÷´æÈ¡º¯ÊýҪƥÅ䣬Êý¾Ý³¤¶ÈҲҪƥÅ䣬·ñÔò»á×èÈû¡£
µÚÈý²½£º¹Ø±ÕÁ¬½Ó¡£´úÂëÈçÏÂ
Dis.close();
Dos.close();
C.close();
·þÎñ¶Ë²¿·Ý
µÚÒ»²½£º½¨Á¢ServerSocket¶ÔÏ󣬵õ½¿Í»§¶ËµÄÁ¬½ÓÇëÇ󣬴úÂëÈçÏ£º
ServerSocket server = new ServerSocket(listenPort);
Socket incomingConnection = null;
while(true) {
incomingConnection = server.accept();
incomingConnection.setSoTimeout(9*60*1000);
handleConnection(incomingConnection);
}
ÆäÖУ¬listenPortÊÇÕìÌý¶Ë¿ÚΪÕûÐÍ¡£¿Í»§Í¬·¢ËÍÇëÇóºó£¬·þÎñ¶ËºÍ¿Í»§¶Ë½¨Á¢Á¬½Ó£¬server.accept·µ»Øsocket¡£
ÀûÓÃsocket£¬µÃµ½¶ÁдÍøÂçÁ÷Êý¾ÝµÄ¶ÔÏó£¬ÆäËüͬ¿Í»§¶ËµÄ±à³Ì·½Ê½¡£ÔÚÍê³É¶ÁдºóÄãÒ²ÐèÒªµ÷ÓÃsocketʵÀýµÄcloseº¯Êý£¬¶Ï¿ªÍ¬¿Í»§¶ËµÄÁ¬½Ó¡£SocketʵÀýµÄsetSoTimeoutÉèÖ㬱£Ö¤ÔÚ¾ÅÃëºó×Ô¶¯¹Ø±Õͬ¿Í»§¶ËµÄÁ¬½Ó¡£
×ܽ᣺
Ïà±ÈC++£¬JavaÌṩµÄAPI·Ç³£ÈÝÒ×ʹÓᣵ«ÊÇҲҪעÒ⼸¸öÎÊÌâ¡£[1]·þÎñ¶ËºÍ¿Í»§¶ËµÄ¶Áдº¯Êý±ØÐëҪƥÅä¡£[2]·þÎñ¶Ëͬ¿Í»§¶ËÖ®¼ä¶
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
£¨1£©¸ù¾ÝxmlÎļþÀ´¹ÜÀíÏ̳߳صÄ×î´ó×îСÏß³ÌÊý
¡¡¡¡£¨2£©¶ÔÏ̳߳Øͨ¹ýTimer¶¨ÆÚɨÃèÒÔ·ÀÖ¹Ïß³Ìδ¼¤»î£»
¡¡¡¡£¨3£©Í¨¹ýijһ¸ö±äÁ¿£¨±¾³ÌÐòÖÐÊÇfreeThreadCount£©À´µÃµ½¿ÕÏÐÏ̵߳ÄÊýÄ¿£»
¡¡¡¡Ò»¡¢ÅäÖÃxml£¨listen.xml£©ÊÇ£º
¡¡¡¡<?xml version="1.0" encoding="UTF-8"?>
¡¡¡¡ <config>
¡¡¡¡ <Con ......
µÚÒ»ÖÖ:
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
ЧÂʸß,ÒÔºóÒ»¶¨ÒªÊ¹ÓôËÖÖ·½Ê½£¡
µÚ¶þÖÖ:
Map map = new HashMap();
Iterato ......
importjava.text.DecimalFormat;
¡¡¡¡
publicclassTestNumberFormat{
¡¡¡¡
¡¡¡¡publicstaticvoidmain(String[]args){
¡¡¡¡¡¡¡¡doublepi=3.1415927;¡¡//Ô²ÖÜÂÊ
¡¡¡¡¡¡¡¡//ȡһλÕûÊý
¡¡¡¡¡¡¡¡System.out.println(newDecimalFormat("0").format(pi));¡¡¡¡¡¡//3
¡¡¡¡¡¡¡¡//ȡһλÕûÊýºÍÁ½Î»Ð¡Êý
¡¡¡¡¡¡¡¡System ......