±À¤¶:| Ãh¥¥¿ç®g | ÀY·w¿ç®g | ¥¢¯v¿ç®g | ÀY¯k¿ç®g | ¸£¸~½F¿ç®g | °O¾Ð»Ùê¿ç®g | ¦Õ·l¶Ë¿ç®g | §íÆ{¿ç®g | Celine Bags | À¦¨à¥Î«~ | Loewe Bag |

µo·s¸ÜÃD
¥´¦L

[ÀÉ®×] Âà¶K:¤@½g¤¶²Ð Java Socket ½sµ{ªº¸g¨å¤å³¹

Âà¶K:¤@½g¤¶²Ð Java Socket ½sµ{ªº¸g¨å¤å³¹

¨Æ¹ê¤Wºô¸ô½sµ{²³æªº²z¸Ñ´N¬O¨â¥x¹q¸£¬Û¤¬³q°T¼Æ¾Ú¦Ó¤w¡C¹ï©óµ{¦¡­û¦Ó¨¥¡A¥h´x´¤¤@ºØ½sµ{¤¶­±¨Ã¨Ï¥Î¤@ºØ½sµ{¼Ò«¬¬Û¹ï´N·|Åã±o²³æªº¦h¤F¡CJava SDK´£¨Ñ¤@¨Ç¬Û¹ï²³æªºApi¨Ó§¹¦¨³o¨Ç¤u§@¡ASocket´N¬O¨ä¤¤¤§¤@¡C

¹ï©óJava¦Ó¨¥¡C³o¨ÇApi¦s¦b»PJava.net³o­Ó¥]ùØ­±¡C¦]¦¹¥u­n¾É¤J³o­Ó¥]´N¥i¥H·Ç³Æºô¸ô½sµ{¤F¡Cºô¸ô½sµ{ªº°ò¥»¼Ò«¬´N¬O«È¤á¾÷¨ì¦øªA¾¹¼Ò«¬¡C²³æªº»¡´N¬O¨â­Ó¶iµ{¤§¶¡¬Û¤¬³q°T¡AµM«á¨ä¤¤¤@­Ó¥²¶·´£¨Ñ¤@­Ó©T©wªº¦ì¸m¡A¦Ó¥t¤@­Ó«h¥u»Ý­nª¾¹D³o­Ó©T©wªº¦ì¸m¡A¨Ã¥h«Ø¥ß¨âªÌ¤§¶¡ªºÁpô¡CµM«á§¹¦¨¼Æ¾Úªº³q°T´N¥i¥H¤F¡C³o¸Ì´£¨Ñ©T©w¦ì¸mªº³q±`ºÙ¬°¦øªA¾¹¡A¦Ó«Ø¥ßÁpôªº³q±`¥s°µ«È¤áºÝ¡C°ò©ó³o­Ó²³æªº¼Ò«¬¡A´N¥i¥H¶i¤Jºô¸ô½sµ{¡C

Java¹ï³o­Ó¼Ò«¬ªº¤ä´©¦³«Ü¦hºØApi.¦Ó³o¸Ì§Ú¥u·Q¤¶²Ð¦³ÃöSocketªº½sµ{¤¶­±¡C¹ï©óJava¦Ó¨¥¤w¸g²¤Æ¤FSocketªº½sµ{¤¶­±¡C­º¥ý§Ú­Ì¨Ó°Q½×¦³Ãö´£¨Ñ©T©w¦ì¸mªºªA°È¤è¬O¦p¦ó«Ø¥ßªº¡CJava´£¨Ñ¤FServerSocket¨Ó¹ï¨ä¶i¦æ¤ä´©¡C¨Æ¹ê¤W·í§A³Ð«Ø¸ÓÃþªº¤@­Ó¹ê¤O¹ï¶H¨Ã´£¨Ñ¤@­ÓºÝ¤f¸ê·½§A´N«Ø¥ß¤F¤@­Ó©T©w¦ì¸m¥i¥HÅý¨ä¥L¹q¸£¨Ó³X°Ý§A¡C

ServerSocket server=new ServerSocket¡]6789¡^¡F

³o¸Ìµy·L­nª`·Nªº¬OºÝ¤fªº¤À°t¥²¶·¬O°ß¤@ªº¡C¦]¬°ºÝ¤f¬O¬°¤F°ß¤@¼ÐÃѨC¥x¹q¸£°ß¤@ªA°Èªº¡C¥t¥~ºÝ¤f¸¹¬O±q0~65535¤§¶¡ªº¡A«e1024­ÓºÝ¤f¤w¸g³QTcp/Ip §@¬°«O¯dºÝ¤f¡A¦]¦¹§A©Ò¤À°tªººÝ¤f¥u¯à¬O1024­Ó¤§«áªº¡C

¦n¤F¡C§Ú­Ì¦³¤F©T©w¦ì¸m¡C²{¦b©Ò»Ý­nªº´N¬O¤@®Ú³s±µ½u¤F¡C¸Ó³s±µ½u¥Ñ«È¤á¤è­º¥ý´£¥X­n¨D¡C¦]¦¹Java¦P¼Ë´£¨Ñ¤F¤@­ÓSocket¹ï¶H¨Ó¹ï¨ä¶i¦æ¤ä´©¡C¥u­n«È¤á¤è³Ð«Ø¤@­ÓSocketªº¹ê¨Ò¹ï¶H¶i¦æ¤ä´©´N¥i¥H¤F¡C

Socket client=new Socket¡]InetAddress.getLocalHost¡]¡^¡A5678¡^¡F

«È¤á¾÷¥²¶·ª¾¹D¦³Ãö¦øªA¾¹ªºIP¦a§}¡C¹ï©óµÛ¤@ÂIJava¤]´£¨Ñ¤F¤@­Ó¬ÛÃöªºÃþInetAddress ¸Ó¹ï¶Hªº¹ê¨Ò¥²¶·³q¹L¥¦ªºÀRºA¤èªk¨Ó´£¨Ñ¡C¥¦ªºÀRºA¤èªk¥D­n´£¨Ñ¤F±o¨ì¥»¾÷IP ©M³q¹L¦W¦r©ÎIPª½±µ±o¨ìInetAddressªº¤èªk¡C

¦n¤F¡A¤W­±ªº¤èªk°ò¥»¥i¥H«Ø¥ß¤@±ø³s½uÅý¨â¥x¹q¸£¬Û¤¬¥æ¬y¤F¡C¥i¬O¼Æ¾Ú¬O¦p¦ó¶Ç¿éªº©O¡H¨Æ¹ê¤WI/O¾Þ§@Á`¬O©Mºô¸ô½sµ{®§®§¬ÛÃöªº¡C¦]¬°©³¼hªººô¸ô¬OÄ~Äò¼Æ¾Úªº¡C°£«D»·µ{½Õ¥Î¡A³B²z°ÝÃDªº®Ö¤ß¦b°õ¦æ¤W¡C

§_«h¼Æ¾Úªº¥æ¤¬ÁÙ¬O¨Ì¿à©óIO¾Þ§@ªº¡C©Ò¥H§A¤]¥²¶·¾É¤JJava.io³o­Ó¥]¡CJavaªºIO¾Þ§@¤]¤£½ÆÂø¡C¥¦´£¨Ñ¤F°w¹ï©ó¦r¸`¬y©MUnicodeªºÅªªÌ©M¼gªÌ¡AµM«á¤]´£¨Ñ¤F¤@­Ó½w½Ä¥Î©ó¼Æ¾ÚªºÅª¼g¡C

BufferedReader in=new BufferedReader¡]new InputStreamReader¡]server.getInputStream¡]¡^¡^¡^¡F

PrintWriter out=new PrintWriter¡]server.getOutputStream¡]¡^¡^¡F

¤W­±¨â¥y´N¬O«Ø¥ß½w½Ä¨Ã§â­ì©lªº¦r¸`¬yÂàÅܬ°Unicode¥i¥H¾Þ§@¡C¦Ó­ì©lªº¦r¸`¬y¨Ó·½©óSocketªº¨â­Ó¤èªk¡AgetInputStream¡]¡^©MgetOutputStream¡]¡^¤è¡A¤À§O¥Î¨Ó±o¨ì¿é¤J©M¿é¥X¡C¨º»ò²{¦b¦³¤F°ò¥»ªº¼Ò«¬©M°ò¥»ªº¾Þ§@¤u¨ã¡A§Ú­Ì¥i¥H°µ¤@­Ó²³æªºSocket¨Òµ{¤FªA°È¤è¡G


import Java¡Cio¡C*;
import Java¡Cnet¡C*;
public class MyServer
{
public static void main
(String[] args) throws IOException
{
ServerSocket server=new
ServerSocket(5678);
Socket client=server.accept();
BufferedReader
in=new BufferedReader(new
InputStreamReader
(client.getInputStream()));
PrintWriter out=new
PrintWriter(client.getOutputStream());
while(true)
{
String str=in.readLine();
System.out.println(str);
out.println("has receive...");
out.flush();
if(str.equals("end"))
break;
}
client¡Cclose();
}
}


³o­Óµ{¦¡ªº¥D­n¥Øªº¦b©ó¦øªA¾¹¤£Â_±µ¦¬«È¤á¾÷©Ò¼g¤Jªº¸ê°T¥u¨ì¡C«È¤á¾÷µo°e"End"¦r²Å¦ê´N°h¥Xµ{¦¡¡C¨Ã¥B¦øªA¾¹¤]·|°µ¥X"Receive"¬°¦^À³¡C§iª¾«È¤á¾÷¤w±µ¦¬¨ì®ø®§¡C«È¤á¾÷¥N½X¡G


import Java.net.*;
import Java.io.*;
public class Client{
static Socket server;
public static void
main(String[] args)
throws Exception
{
server=new Socket
(InetAddress.getLocalHost()¡A5678);
BufferedReader in=new BufferedReader(new
InputStreamReader(server¡CgetInputStream()));
PrintWriter out=new
PrintWriter(server.getOutputStream());
BufferedReader wt=new BufferedReader(new
InputStreamReader(System.in));
while(true)
{
  String str=wt.readLine();
  out.println(str);
  out.flush();
  if(str.equals("end"))
  {
  break;
  }
  System.out.println(in.readLine());
}
server.close();
}
}



http://big5.ccidnet.com:89/gate/ ... 1112/1272239_1.html


¬ÛÃö·j¯Á¥Ø¿ý: ¹q¸£ ¼Ò«¬

TOP

thanks for sharing

TOP

thx"""""""""""
¯u«Y¦n¦³¥Î"

TOP

thanks for sharing

TOP

thanks for sharing

TOP

µo·s¸ÜÃD


­«­nÁn©ú¡G¥»°Q½×°Ï¬O¥H§Y®É¤W¸ü¯d¨¥ªº¤è¦¡¹B§@¡A¥»ºô¯¸¹ï©Ò¦³¯d¨¥ªº¯u¹ê©Ê¡B§¹¾ã©Ê¤Î¥ß³õµ¥¡A¤£­t¥ô¦óªk«ß³d¥ô¡C¦Ó¤@¤Á¯d¨¥¤§¨¥½×¥u¥Nªí¯d¨¥ªÌ­Ó¤H·N¨£¡A¨Ã«D¥»ºô¯¸¤§¥ß³õ¡A¥Î¤á¤£À³«H¿à¤º®e¡A¨ÃÀ³¦Û¦æ§PÂ_¤º®e¤§¯u¹ê©Ê¡C©ó¦³Ãö±¡§Î¤U¡A¥Î¤áÀ³´M¨D±M·~·N¨£(¦p¯A¤ÎÂåÀø¡Bªk«ß©Î§ë¸êµ¥°ÝÃD)¡C¥Ñ©ó¥»°Q½×°Ï¨ü¨ì¡u§Y®É¤W¸ü¯d¨¥¡v¹B§@¤è¦¡©Ò³W­­¡A¬G¤£¯à§¹¥þºÊ¹î©Ò¦³¯d¨¥¡A­YŪªÌµo²{¦³¯d¨¥¥X²{°ÝÃD¡A½ÐÁpµ¸§Ú­Ì¡C¥»°Q½×°Ï¦³Åv§R°£¥ô¦ó¯d¨¥¤Î©Úµ´¥ô¦ó¤H¤h¤W¸ü¯d¨¥¡A¦P®É¥ç¦³¤£§R°£¯d¨¥ªºÅv§Q¡C¤Á¤Å¼¶¼g²Ê¨¥Â©»y¡B½ÚÁ½¡B´è¬V¦â±¡¼É¤O©Î¤H¨­§ðÀ»ªº¨¥½×¡A·q½Ð¦Û«ß¡C¥»ºô¯¸«O¯d¤@¤Áªk«ßÅv§Q¡C


Copyright 1997- Xocat. All Right Reserved.