Java ÀûÓÃÌ×½Ó×ÖSocketʵÏÖ¼òµ¥µÄ·þÎñÆ÷Óë¿Í»§¶ËͨÐÅ
ÎÒÃÇҪʵÏֵľßÌ幦ÄÜÊÇ£º
ÀûÓÃSocketÀàºÍServerSocketÀà±àдһ¸öC/S³ÌÐò£¬ÊµÏÖC/SͨÐÅ¡£
¿Í»§¶ËÏò·þÎñÆ÷¶Ë·¢ËÍTimeÃüÁ·þÎñÆ÷¶Ë½ÓÊܵ½¸Ã×Ö·û´®ºó½«·þÎñÆ÷¶Ëµ±Ç°Ê±¼ä·µ»Ø¸ø¿Í»§¶Ë£»¿Í»§¶ËÏò·þÎñÆ÷¶Ë·¢ËÍExitÃüÁ·þÎñÆ÷¶ËÏò¿Í»§¶Ë·µ»Ø“Bye”ºóÍ˳ö¡£
ÌâÄ¿±È½Ï¼òµ¥µÄ£¬ÎÒÃÇÖ±½ÓÀ´¿´´úÂë°É£º
Ê×ÏÈÊÇ·þÎñÆ÷¶ËµÄʵÏÖ£º
import java.net.ServerSocket;
import java.net.Socket;
import java.io.*;
import java.text.DateFormat;
import java.util.Date;//ʱ¼ä
//import java.util.Calendar;
public class Server {
public static void main(String args[]){
try{
ServerSocket server = new ServerSocket(11111);//´´½¨·þÎñÆ÷Ì×½Ó×Ö
System.out.println("·þÎñÆ÷Æô¶¯Íê±Ï");
System.out.println("µÈ´ý¿Í»§¶ËÁ¬½Ó...");
Socket socket = server.accept();//µÈ´ý¿Í»§¶ËÁ¬½Ó
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));//»ñµÃ¿Í»§¶ËµÄÊäÈëÁ÷
//OutputStreamWriter out = new OutputStreamWriter(socket.getOutputStream());//»ñµÃ¿Í»§¶ËÊä³öÁ÷
PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);//»ñµÃ¿Í»§¶ËÊä³öÁ÷)
if(socket.isConnected()){
System.out.println("¿Í»§¶ËÃû³ÆΪ"+socket.getInetAddress().getHostAddress()+" Á¬½Ó³É¹¦£¡");
//out.write("Á¬½Ó³É¹¦\n");
out.println("Á¬½Ó³É¹¦");
}
while(true){
String str = reader.readLine();
if(str.equals("Time")){//¿Í»§¶ËÇëÇóʱ¼äÊý¾Ý
Date date = new Date();
// Calendar cal = Calendar.getInstance();
System.out.println("¿Í»§¶ËÇëÇóµ±Ç°Ê±¼ä");
DateFormat format = DateFormat.getDateInstance();
//out.write(format.format(date));//¸ñʽ»¯Êä³öʱ¼ä
out.println(format.format(date));
}
else if(str.equals("exit")){//Í˳ö
//out.write("bye");
out.println("bye");
System.out.println("Á¬½Ó¶Ï¿ª");
break;
}
else{
System.out.println("Êý¾Ý£º"+str);
}
}
}catch(IOException e){
e.pr
Ïà¹ØÎĵµ£º
TIOBE
µÄ
±à³ÌÓïÑÔÅÅÃû°ñ£¬Ïë±Ø´ó¼Ò¶¼·Ç³£ÊìϤ£¬Ã¿Ô·¢²¼È«Çò±à³ÌÓïÑÔµÄÈȶȺÍÇ÷ÊÆ¡£ÔÚËÄÔ·ݷ¢²¼µÄÊý¾ÝÖУ¬CÓïÑÔÖÕÓÚ³¬¹ýJava³ÉΪNo.1£¬µ«ÕæÕýÈÃÈ˵£ÓÇ
µÄ£¬²¢²»ÊÇCµÄ¶á¹Ú£¬¶øÊÇJavaµÄ³ÖÐøÆ£Èõ£¬¸üÔã¸âµÄÊÇ£¬ËƺõûÓÐÄĸöÀÏ´óÕ¾³öÀ´Íì¾ÈÍÇÊÆ¡£
×÷ΪһÃûJava´ÓÒµÕߣ¬ÎÒÔÚÆóÒµÓ¦ÓÃÁìÓò×öÈí¼þ£¬´Ó¹¤×÷Öв¢Î´¸ÐÊܵ½Javaµ ......
ת×Ô£ºhttp://blog.csdn.net/daijialin/archive/2004/12/27/231384.aspx
ÔÚJDK 1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO API×÷Î ......
¼ò»¯Í¼£º
Javaƽ̨ÌṩÁËÒ»¸öȫеļ¯ºÏ¿ò¼Ü¡£“¼¯ºÏ¿ò¼Ü”Ö÷ÒªÓÉÒ»×éÓÃÀ´²Ù×÷¶ÔÏóµÄ½Ó¿Ú×é³É¡£²»Í¬½Ó¿ÚÃèÊöÒ»×鲻ͬÊý¾ÝÀàÐÍ¡£
Java 2¼¯ºÏ¿ò¼Üͼ
¼¯ºÏ½Ó¿Ú£º6¸ö½Ó¿Ú£¨¶ÌÐéÏß±íʾ£©£¬±íʾ²»Í¬¼¯ºÏÀàÐÍ£¬ÊǼ¯ºÏ¿ò¼ÜµÄ»ù´¡¡£
³éÏóÀࣺ5¸ö³éÏóÀࣨ³¤ÐéÏß±íʾ£©£¬¶Ô¼¯ºÏ½Ó¿ÚµÄ²¿·ÖʵÏÖ¡£¿ÉÀ©Õ¹Îª×Ô¶¨Ò弯ºÏÀà¡£ ......
ÃæÊÔÖÐÓöµ½µÄÎÊÌ⣬´ó¼Ò¹²Í¬Ñ§Ï°£¡£¡
Java¹¤³§Ä£Ê½
Java¹¤³§Ä£Ê½¿´ÁËÕâô¶à¹ØÓÚ¹¤³§Ä£Ê½µÄ½²½â£¬»¹ÊǾõµÃÕâƪÎÄÕ½²µÄºÃÀí½â£¬Ìù³öÀ´ºÍ´ó¼Ò·ÖÏí·ÖÏí¡£
Ò»¡¢Òý×Ó
»°ËµÊ®ÄêÇ°£¬ÓÐÒ»¸ö****»§£¬Ëû¼ÒÓÐÈýÁ¾Æû³µ——Benz±¼³Û¡¢Bmw±¦Âí¡¢Audi°ÂµÏ£¬»¹¹ÍÁË˾»úΪËû¿ª³µ¡£²»¹ý£¬****»§×ø³µÊ±×ÜÊǹֵֹģºÉÏBenz³µºó ......