Java Socket
×î½üÑо¿ÏÂsocket,ctrl+vÁËÏÂÍøÉϵĶ«Î÷:
ÊÂʵÉÏÍøÂç±à³Ì¼òµ¥µÄÀí½â¾ÍÊÇÁ½Ì¨¼ÆËã»úÏ໥ͨѶÊý¾Ý¶øÒÑ¡£¶ÔÓÚ³ÌÐòÔ±¶øÑÔ£¬È¥ÕÆÎÕÒ»ÖÖ±à³Ì½Ó¿Ú²¢Ê¹ÓÃÒ»ÖÖ±à³ÌÄ£ÐÍÏà¶Ô¾Í»áÏԵüòµ¥µÄ¶àÁË¡£Java SDKÌṩһЩÏà¶Ô¼òµ¥µÄApiÀ´Íê³ÉÕâЩ¹¤×÷£¬Socket¾ÍÊÇÆäÖÐÖ®Ò»¡£
¡¡¡¡¶ÔÓÚJava¶øÑÔ¡£ÕâЩApi´æÔÚÓëJava.netÕâ¸ö°üÀïÃæ¡£Òò´ËÖ»Òªµ¼ÈëÕâ¸ö°ü¾Í¿ÉÒÔ×¼±¸ÍøÂç±à³ÌÁË¡£ÍøÂç±à³ÌµÄ»ù±¾Ä£Ð;ÍÊÇ¿Í»§»úµ½·þÎñÆ÷Ä£ÐÍ¡£¼òµ¥µÄ˵¾ÍÊÇÁ½¸ö½ø³ÌÖ®¼äÏ໥ͨѶ£¬È»ºóÆäÖÐÒ»¸ö±ØÐëÌṩһ¸ö¹Ì¶¨µÄλÖ㬶øÁíÒ»¸öÔòÖ»ÐèÒªÖªµÀÕâ¸ö¹Ì¶¨µÄλÖ㬲¢È¥½¨Á¢Á½ÕßÖ®¼äµÄÁªÏµ¡£È»ºóÍê³ÉÊý¾ÝµÄͨѶ¾Í¿ÉÒÔÁË¡£ÕâÀïÌṩ¹Ì¶¨Î»ÖõÄͨ³£³ÆΪ·þÎñÆ÷£¬¶ø½¨Á¢ÁªÏµµÄͨ³£½Ð×ö¿Í»§¶Ë¡£»ùÓÚÕâ¸ö¼òµ¥µÄÄ£ÐÍ£¬¾Í¿ÉÒÔ½øÈëÍøÂç±à³Ì¡£
¡¡¡¡Java¶ÔÕâ¸öÄ£Ð͵ÄÖ§³ÖÓкܶàÖÖApi.¶øÕâÀïÎÒÖ»Ïë½éÉÜÓйØSocketµÄ±à³Ì½Ó¿Ú¡£¶ÔÓÚJava¶øÑÔÒѾ¼ò»¯ÁËSocketµÄ±à³Ì½Ó¿Ú¡£Ê×ÏÈÎÒÃÇÀ´ÌÖÂÛÓйØÌṩ¹Ì¶¨Î»ÖõķþÎñ·½ÊÇÈçºÎ½¨Á¢µÄ¡£JavaÌṩÁËServerSocketÀ´¶ÔÆä½øÐÐÖ§³Ö¡£ÊÂʵÉϵ±Äã´´½¨¸ÃÀàµÄÒ»¸öʵÁ¦¶ÔÏó²¢Ìṩһ¸ö¶Ë¿Ú×ÊÔ´Äã¾Í½¨Á¢ÁËÒ»¸ö¹Ì¶¨Î»ÖÿÉÒÔÈÃÆäËû¼ÆËã»úÀ´·ÃÎÊÄã¡£
¡¡¡¡ServerSocket server=new
¡¡¡¡ServerSocket£¨6789£©£»
¡¡¡¡ÕâÀïÉÔ΢ҪעÒâµÄÊǶ˿ڵķÖÅä±ØÐëÊÇΨһµÄ¡£ÒòΪ¶Ë¿ÚÊÇΪÁËΨһ±êʶÿ̨¼ÆËã»úΨһ·þÎñµÄ¡£ÁíÍâ¶Ë¿ÚºÅÊÇ´Ó0~65535Ö®¼äµÄ£¬Ç°1024¸ö¶Ë¿ÚÒѾ±»Tcp/Ip ×÷Ϊ±£Áô¶Ë¿Ú£¬Òò´ËÄãËù·ÖÅäµÄ¶Ë¿ÚÖ»ÄÜÊÇ1024¸öÖ®ºóµÄ¡£
¡¡¡¡ºÃÁË¡£ÎÒÃÇÓÐÁ˹̶¨Î»Öá£ÏÖÔÚËùÐèÒªµÄ¾ÍÊÇÒ»¸ùÁ¬½ÓÏßÁË¡£¸ÃÁ¬½ÓÏßÓÉ¿Í»§·½Ê×ÏÈÌá³öÒªÇó¡£Òò´ËJavaͬÑùÌṩÁËÒ»¸öSocket¶ÔÏóÀ´¶ÔÆä½øÐÐÖ§³Ö¡£Ö»Òª¿Í»§·½´´½¨Ò»¸öSocketµÄʵÀý¶ÔÏó½øÐÐÖ§³Ö¾Í¿ÉÒÔÁË¡£
¡¡¡¡Socket client=new
¡¡¡¡Socket£¨InetAddress.getLocalHost£¨£©£¬5678£©£»
¡¡¡¡¿Í»§»ú±ØÐëÖªµÀÓйطþÎñÆ÷µÄIPµØÖ·¡£¶ÔÓÚ×ÅÒ»µãJavaÒ²ÌṩÁËÒ»¸öÏà¹ØµÄÀàInetAddress ¸Ã¶ÔÏóµÄʵÀý±ØÐëͨ¹ýËüµÄ¾²Ì¬·½·¨À´Ìṩ¡£ËüµÄ¾²Ì¬·½·¨Ö÷ÒªÌṩÁ˵õ½±¾»úIP ºÍͨ¹ýÃû×Ö»òIPÖ±½ÓµÃµ½InetAddressµÄ·½·¨¡£
¡¡¡¡ºÃÁË£¬ÉÏÃæµÄ·½·¨»ù±¾¿ÉÒÔ½¨Á¢Ò»ÌõÁ¬ÏßÈÃÁ½Ì¨¼ÆËã»úÏ໥½»Á÷ÁË¡£¿ÉÊÇÊý¾ÝÊÇÈçºÎ´«ÊäµÄÄØ£¿ÊÂʵÉÏI/O²Ù×÷×ÜÊǺÍÍøÂç±à³ÌϢϢÏà¹ØµÄ¡£ÒòΪµ×²ãµÄÍøÂçÊǼÌÐøÊý¾ÝµÄ¡£³ý·ÇÔ¶³Ìµ÷Ó㬴¦ÀíÎÊÌâµÄºËÐÄÔÚÖ´ÐÐÉÏ¡£
¡¡¡¡·ñÔòÊý¾ÝµÄ½»»¥»¹ÊÇÒÀÀµÓÚIO²Ù×÷µÄ¡£ËùÒÔÄãÒ²±ØÐëµ¼ÈëJava.ioÕâ¸ö°ü¡£JavaµÄIO²Ù×÷Ò²²»¸´ÔÓ¡£ËüÌṩÁËÕë¶ÔÓÚ×Ö½ÚÁ÷ºÍUnicodeµÄ¶ÁÕߺÍÐ
Ïà¹ØÎĵµ£º
equals ·½·¨ÊÇ java.lang.Object ÀàµÄ·½·¨¡£
ÓÐÁ½ÖÖÓ÷¨ËµÃ÷£º
£¨1£©¶ÔÓÚ×Ö·û´®±äÁ¿À´Ëµ£¬Ê¹ÓÓ==”ºÍ“equals()”·½·¨±È½Ï×Ö·û´®Ê±£¬Æä±È½Ï·½·¨²»Í¬¡£
“==”±È½ÏÁ½¸ö±äÁ¿±¾ÉíµÄÖµ£¬¼´Á½¸ö¶ÔÏóÔÚÄÚ´æÖеÄÊ×µØÖ·¡£
“equals()”±È½Ï×Ö·û´®ÖÐËù°üº¬µÄÄÚÈÝÊÇ·ñÏàͬ¡£
±ÈÈ磺
......
For Ubuntu 10.04 LTS, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Reposi ......
À´µ½±±¾©´«ÖDz¥¿ÍÒ»ÔÂÓÐÓà ÉîÓид¥
ÕýËùνı¶¨¶øºó¶¯ Ãæ¶Ô¹úÄÚ·×˵ÖÚÜ¿µÄÅàѵ»ú¹¹ °³ºÜÔÎ
ÏÈ˵˵µØÀíλÖÃ×î½üµÄ±¾ÍÁÅàѵ»ú¹¹°É òËƽÌѧʱ¼ä±È½Ï³¤ ÒªÒ»ÄêÖ®¾Ã Ö÷ÒªÕÐÊÕÔÚУ´óѧÉú ½Ìѧʱ¼äÊÇÍíÉÏ µÚÒ»¸ö±»±»ÈËpass
´Ó¶ø¿ªÊ¼Ñ°ÕÒÔÚÊ¡»áµÄÅàѵ»ú¹¹ òËÆѧ·ÑÌ«¹ó ºÍ±¾ÈËÔ¤ËãÓÐËù³åÍ» pass
×îºóÎÒÖÕÓÚÕ ......
1.¼ÆËãijһÔ·ݵÄ×î´óÌìÊý
Calendar time=Calendar.getInstance();
time.clear();
time.set(Calendar.YEAR,year); //year Ϊ int
time.set(Calendar.MONTH,i-1);//×¢Òâ,Calendar¶ÔÏóĬÈÏÒ»ÔÂΪ0
int day=time.getActualMaximum(Calendar.DAY_OF_MONTH);//±¾Ô·ݵÄÌìÊý
×¢£ºÔÚʹÓÃset·½·¨Ö®Ç°£¬±ØÐëÏÈ ......