IBM Korea Skip to main content
       IBM Ȩ    |  Á¦Ç° & ¼­ºñ½º  |  °í°´Áö¿ø & ´Ù¿î·Îµå  |  È¸¿ø°¡ÀÔ  

IBM developerWorks > ÀÚ¹Ù
developerWorks

¸ð¹ÙÀÏ P2P ¸Þ½Ã¡, Part 2 : ÀϹÝÀûÀÎ P2P ³×Æ®¿öÅ©·Î ¸ð¹ÙÀÏ È®Àå °³¹ßÇϱâ
¸ð¹ÙÀÏ µð¹ÙÀ̽º¸¦ JXTA¿Í Jabber Ŭ¶óÀ̾ðÆ®·Î ÀüȯÇϱâ

Level: Intermediate

Michael Juntao Yuan
University of Texas at Austin, ÀüÀÚ»ó°Å·¡ ¼¾ÅÍ, ¿¬±¸¿ø
2003³â 1¿ù 1ÀÏ

JXTA¿Í Jabber °°Àº ÀϹÝÀûÀÎ P2P ÄÄÇ»Æà ³×Æ®¿öÅ©´Â ¸ð¹ÙÀÏ µð¹ÙÀ̽º¿¡ Àû¿ëÇϱ⿡´Â ³Ê¹« º¹ÀâÇÏ´Ù. µû¶ó¼­ °æ·® ¸ð¹ÙÀÏ Å¬¶óÀ̾ðÆ®³ª ¸±·¹ÀÌ(relay)¸¦ ÅëÇØ ÀÛµ¿Çϴ Ưº°ÇÑ ¾ÆÅ°ÅØÃÄ´Â P2P Ä¿¹Â´ÏƼ¸¦ ¸ð¹ÙÀÏ »ç¿ëÀÚ·Î È®´ëµÇ¾î¾ß ÇÑ´Ù. Michael YuanÀº J2ME JXTA Ŭ¶óÀ̾ðÆ® ÇÁ·ÎÁ§Æ®ÀÎ JXME¸¦ ¼³¸íÇÑ´Ù.

SMS ±â¹Ý ¸Þ½Ã¡Àº ¹«¼± ÀüÈ­ »ç¿ëÀڵ鿡°Ô´Â ¸Å¿ì Æí¸®ÇÏ´Ù. ÇÏÁö¸¸, PDA¿Í WAN ¿¬°á ÇÚµåÇïµå °°Àº ¸ð¹ÙÀÏ ÀåÄ¡¿¡´Â ÇÕ´çÇÑ ¸Þ½Ã¡ Ç÷§ÆûÀÌ ¾Æ´Ï´Ù. ´Ù¾çÇÑ ¼¿ ³×Æ®¿öÅ©(±¹Á¦ ÀüÈ­)¸¦ ÅëÇÑ SMS ¸Þ½Ã¡ ¿ª½Ã °ªÀÌ ºñ½Î°Å³ª ¾î¶² °æ¿ì´Â ºÒ°¡´ÉÇÏ´Ù. ÀÌ ±Û¿¡¼­´Â µÎ °³ÀÇ ¹ü¿ë P2P ³×Æ®¿öÅ©ÀÎ JXTA P2P¿Í Jabber ÀνºÅÏÆ® ¸Þ½Ã¡ ³×Æ®¿öÅ©¸¦ ¼Ò°³ÇÏ°Ú´Ù.

JXTA ÇÁ·¹ÀÓ¿÷
JXTA´Â P2P ³×Æ®¿öÅ©¿ë ¿ÀÇ ÇÁ·ÎÅäÄÝÀ» Á¤ÀÇÇÑ´Ù. ÀÌ XML ±â¹ÝÀÇ ÇÁ·ÎÅäÄÝÀº ÇÇ¾î µð½ºÄ¿¹ö¸®, ¿£µåÆ÷ÀÎÆ® ¶ó¿ìÆÃ, Ä¿³Ø¼Ç ¹ÙÀεù, ±âº» Äõ¸®/ÀÀ´ä ¸Þ½ÃÁö ±³È¯, ¶ûµ¥ºÎ ÇǾ ÅëÇÑ ³×Æ®¿öÅ© ÆÄ±Þ °°Àº º¹ÀâÇÑ ÀÛµ¿À» Á¤ÀÇÇÑ´Ù. JXTA ³×Æ®¿öÅ©´Â ´ÙÀ½°ú °°Àº ÄÄÆ÷³ÍÆ®·Î ±¸¼ºµÇ¾î ÀÖ´Ù:

  • ÇǾî(peer)´Â JXTA ³×Æ®¿öÅ©ÀÇ ±âº»ÀûÀÎ ¿¤¸®¸ÕÆ®ÀÌ´Ù. ÇǾî´Â ÇÙ½É JXTA ÇÁ·ÎÅäÄÝÀ» ±¸ÇöÇÏ°í ¸ðµç ´Ù¸¥ ÇǾîµé°ú µ¶¸³ÀûÀÌ°í ºñµ¿±â½ÄÀ¸·Î ÀÛµ¿ÇÑ´Ù. ÇǾî´Â ¾ÖÇø®ÄÉÀ̼ǰú ³×Æ®¿öÅ© ¼­ºñ½º¸¦ Á¦°øÇÏ°í ÇǾî ÀÚü¸¦ ±¤°íÇÒ ¼ö ÀÖ´Ù.
  • ÇÇ¾î ±×·ìÀº ÇǾîµéÀÇ ¸ðÀ½ÀÌ´Ù. JXTA´Â ±×·ìÀ» ¸¸µé°í Âü¿©ÇÏ°í °¨½ÃÇϱâ À§ÇØ ÇǾîµéÀÌ »ç¿ëÇÏ´Â ÇÁ·ÎÅäÄÝÀ» Á¤ÀÇÇÑ´Ù. ±×·ìÀº ÇÇ¾î ¹ß°ß, ¸â¹ö½±, ¾×¼¼½º Á¦¾î, ÆÄÀÌÇÁ, Ŭ¶óÀ̾ðÆ®(resolver), ¸ð´ÏÅ͸µ °°Àº ¼­ºñ½º¸¦ Á¦°øÇÑ´Ù.
  • ÆÄÀÌÇÁ(Pipe)´Â ÇǾîµé °£ °¡»ó ¿¬°áÀ» ³ªÅ¸³½´Ù. point-to-point ÆÄÀÌÇÁ´Â µÎ °³ÀÇ ÇǾ ¿¬°áÇÑ´Ù. propagate ÆÄÀÌÇÁ´Â ¹æ¼Û ÇǾ ´ÙÁß ¸®½º³Ê¿¡ ¿¬°áÇÑ´Ù. ÆÄÀÌÇÁ°¡ ¿¬°áµÈ ÇǾîµéÀº Á÷Á¢ ¹°¸®Àû ¸µÅ©°¡ µÉ ÇÊ¿ä´Â ¾ø´Ù. ¿©·¯ °³ÀÇ Áß°£ ÆÄÀÌÇÁ¸¦ ÅëÇØ ¿¬°áµÉ ¼ö Àֱ⠶§¹®ÀÌ´Ù.
  • ¸Þ½ÃÁö(Message)´Â ÇǾîµé°ú ¿£µåÆ÷ÀÎÆ® °£, ÆÄÀÌÇÁ¸¦ ÅëÇØ ±³È¯µÇ´Â µ¥ÀÌÅÍÀÌ´Ù. JXTA´Â ¸ðµç ¸Þ½ÃÁö¿ë envelope Æ÷¸ËÀ» Á¤ÀÇÇÑ´Ù. °¢ ÇǾî´Â ÀÚ½ÅÀÇ ¸Þ½ÃÁö ÄÁÅÙÆ® Æ÷¸ËÀ» Á¤ÀÇÇÒ ¼ö ÀÖ´Ù. ´Ü Æ÷¸ËÀº XML ½ºÆÑ¿¡ ȣȯµÇ¾î¾ß ÇÑ´Ù. ÇÏÁö¸¸ µÎ °³ÀÇ ÇǾîµéÀÌ Á¤º¸¸¦ ±³È¯Çϱâ À§Çؼ­´Â »ó´ë¹æÀÇ ¸Þ½ÃÁö Æ÷¸ËÀ» ÀÌÇØÇØ¾ß ÇÑ´Ù.
  • ±¤°í(Advertisement)´Â JXTA ³×Æ®¿öÅ© ¸®¼Ò½º¸¦ ±â¼úÇϱâ À§ÇÑ ¸ÞŸµ¥ÀÌÅÍ ±¸Á¶ÀÌ´Ù. ¸ðµç ÇǾîµé°ú ¼­ºñ½ºµéÀº ±¤°í¸¦ ÀÌÇØÇÑ´Ù.

JXTA´Â ´Ü¼øÇÑ ¸Þ½ÃÁö±³È¯ ÀÌ»óÀÇ P2P ÇÁ·¹ÀÓ¿÷ÀÌ´Ù. P2P ÆÄÀÏ °øÀ¯, P2P ¾ÖÇø®ÄÉÀÌ¼Ç ¼­ºñ½º, Çù¾÷ ºÐ»ê ÄÄÇ»Æà °°Àº ¹®Á¦¸¦ ´Ù·ç°íÀÖ´Ù. JXTA ÇÁ·ÎÅäÄÝÀº ¸ðµç ±¸Çö ±â¼ú¿¡ µ¶¸³ÀûÀ¸·Î ¼³°èµÈ ¹Ý¸é JXTAÀÇ ·¹ÆÛ·±½º ±¸ÇöÀº ÀÚ¹Ù Ç÷§Æû¿¡ ±¸ÇöµÈ´Ù. ÀÌ ·¹ÆÛ·±½º ±¸ÇöÀº ÀÚ¹Ù API¸¦ »ç¿ëÇÏ¿© JXTA ÇÁ·ÎÅäÄÝ ¸Þ½ÃÁö¸¦ ·¡ÇÎÇÏ°í ÇÁ·Î±×·¥ ¹æ¹ýÀ¸·Î ÀÚ¹Ù ¾ÖÇø®ÄÉÀ̼ǿ¡¼­ JXTA ³×Æ®¿öÅ©¿¡ ¾×¼¼½ºÇÑ´Ù.

¸ð¹ÙÀÏ ÀåÄ¡¿ë JXTA
JXTAÀÇ Èû°ú À¯¿¬¼ºÀº º¹À⼺À̶ó´Â »ó´çÇÑ ´ë°¡¸¦ Ä¡¸£°í ¾ò¾îÁ³´Ù. JXTA ÇǾî´Â ¸¹Àº ŽºÅ©¸¦ °ü¸®ÇÏ°í XML-¼ÒÄÏ ·¹º§¿¡¼­ ¸Þ½ÃÁö¸¦ ó¸®ÇÑ´Ù. ±×¿Í °°Àº ÇǾî´Â ³Ê¹«³ª º¹ÀâÇؼ­ ´ëºÎºÐÀÇ ¸ð¹ÙÀÏ µð¹ÙÀ̽º »ó¿¡¼­´Â ½ÇÇàÇÒ ¼ö ¾ø´Ù. °Ô´Ù°¡, XMLÀ̳ª ¿ø·¡ÀÇ ¼ÒÄÏ Áö¿øÀº Ç¥ÁØ J2ME/MIDP ½ºÆÑÀÇ ÀϺÎÀÌ´Ù. ¸ð¹ÙÀÏ P2P »ç¿ëÀڵ鿡°Ô JXTA ³×Æ®¿öÅ©¸¦ °¡´ÉÇÏ°Ô ÇÏ·Á¸é ¸ð¹ÙÀÏ µð¹ÙÀ̽º¿ë JXTA API°¡ ÇÊ¿äÇÏ´Ù. JXME ÇÁ·ÎÁ§Æ®´Â JXTA API¸¦ CLDC¿Í MIDP Ç÷§Æû¿¡ Á¦°øÇÏ´Â °ÍÀ» ¸ñÇ¥·ÎÇÏ°í ÀÖ´Ù. ÀÌ°ÍÀº Personal Profile °°Àº J2ME ÇÁ·ÎÆÄÀÏ¿¡µµ »ç¿ëµÈ´Ù.

JXMEÀº ¸±·¹ÀÌ(relay)¸¦ »ç¿ëÇÏ¿© °æ·®ÀÇ ¸ð¹ÙÀÏ ÇǾîµéÀ» ³ª¸ÓÁö JXTA ³×Æ®¿öÅ©¿¡ ¿¬°áÇÑ´Ù. ¸±·¹ÀÌ ÀÚü·Î´Â ¶ûµ¥ºÎ JXTA ÇǾî·Î¼­ ÆÄÀÌÇÁ, ±¤°í, ÇÇ¾î ±×·ì ¼­ºñ½º¸¦ ÇÚµéÇÒ ¼ö ÀÖ´Ù. ¸ð¹ÙÀÏ ÇǾî´Â HTTP¸¦ ÅëÇÑ ¹ÙÀ̳ʸ® ¿¬°áÀ» ÅëÇØ ¸±·¹À̵é°ú Åë½ÅÇÑ´Ù. À̶§ JXTA Binary Message Æ÷¸Ë¿¡ ¼øÀÀÇÏ´Â ¸Þ½ÃÁö¸¦ »ç¿ëÇÑ´Ù. ¸±·¹ÀÌ´Â ¸ð¹ÙÀÏ ÇǾîµé¿¡°Ô ¸¹Àº ÇÇ¾î ¼­ºñ½º¸¦ Á¦°øÇÑ´Ù:

  • ¸±·¹ÀÌ´Â ºÒÇÊ¿äÇÑ ±¤°í¸¦ °É·¯³»°í ±×·± ±¤°íµéÀ» ¾ø¾Ö ´ë¿ªÆøÀ» ÀúÀåÇÑ´Ù.
  • ¸±·¹ÀÌ´Â ¸Þ½ÃÁöµéÀ» ¸ð¹ÙÀÏ ÇǾîµé¿¡ ¶ó¿ìÆÃÇÑ´Ù.
  • ¸±·¹ÀÌ´Â JXTA XML Æ÷¸Ë¿¡¼­ JXTA Binary Message Æ÷¸ËÀ¸·Î ¸Þ½ÃÁöµéÀ» º¯È¯ÇÑ´Ù. ±× ¹Ý´ëµµ ¼öÇàÇÑ´Ù. ¸ð¹ÙÀÏ ÇǾî¿Í ÀÏ»ó ÇǾîµé °£ »óÈ£¿î¿ë¼ºÀ» À§Çؼ­ÀÌ´Ù.
  • ¸±·¹ÀÌ´Â ¸ð¹ÙÀÏ ÇǾ ´ë½ÅÇÏ¿© ÇÁ·Ï½Ã·Î¼­ ÀÛµ¿ÇÑ´Ù. ¸±·¹ÀÌ´Â ´Ù¸¥ ÇǾî¿Í ÆÄÀÌÇÁ¿Í ÀÎÅÍ·¢ÆÃÇÏ°í ±×·ì ¼­ºñ½º¸¦ »ç¿ëÇÑ´Ù.

±×¸² 1. JXME ¾ÆÅ°ÅØÃÄ
JXME architecture

JXME API

JXME ÆÐÅ°Áö¸¦ ´Ù¿î·ÎµåÇÏ¸é µ¥¸ð¸¦ ½ÇÇàÇÒ ¼ö ÀÖ´Ù. ´Ù¿î·Îµå ÆÐÅ°Áö¿¡ Æ÷ÇÔµÈ Ant ±¸Çö ½ºÅ©¸³Æ®¸¦ »ç¿ëÇÏ¿© ´Ü°èº°·Î µ¥¸ð¸¦ ½ÇÇàÇÑ´Ù. ÀÚ¼¼ÇÑ Æ©Å丮¾óÀº JXME À¥ »çÀÌÆ®¸¦ ÂüÁ¶ÇÑ´Ù.

¿ì¼±, ¸ð¹ÙÀÏ µð¹ÙÀ̽º¿Í ¸ñÇ¥ JXTA Ä¿¹Â´ÏƼ¿¡¼­ Á¢±Ù °¡´ÉÇÑ ÄÄÇ»ÅÍ¿¡ ¸±·¹ÀÌ ÇǾ ½ÇÇàÇØ¾ß ÇÑ´Ù. proxy µð·ºÅ丮ÀÇ build.xml ÆÄÀÏ¿¡´Â runproxy ŽºÅ©°¡ Æ÷ÇԵǾî ÀÖ¾î JXMEÀ» ¸±·¹À̸¦ ½ÇÇàÇÑ´Ù. Àû´çÇÑ ¹Ú½º¸¦ Á¡°ËÇÏ¿© Rendevous, relay, JxtaProxy ·Î¼­ ½ÇÇàÇÑ´Ù. ÀÌÁ¦ JXME ÇǾ ½ÇÇàÇÒ ¼ö ÀÖ´Ù. ´Ù¿î·Îµå ÆÐÅ°Áö¿¡´Â µÎ°³ÀÇ »ùÇà JXME ¾ÖÇø®ÄÉÀ̼Ç(chat & tictactoe)ÀÌ Æ÷ÇԵǾî ÀÖ´Ù.

JXME ÆÐÅ°Áö¸¦ º¸ÀÚ. JXME API´Â ¼¼ °³ÀÇ Å¬·¡½º¸¦ °¡Áö°í ÀÖÀ¸¸ç ¸ðµÎ net.jxta.j2me ÆÐÅ°Áö¿¡ ÀÖ´Ù:

  • Element´Â JXTA ¸Þ½ÃÁö ³»ÀÇ ¿¤¸®¸ÕÆ®ÀÌ´Ù. ¿¤¸®¸ÕÆ®¿¡´Â ³×ÀÓ, ³×ÀÓ½ºÆäÀ̽º, MIME ŸÀÔ, µ¥ÀÌÅÍÀÇ ¹ÙÀ̳ʸ® ¾î·¹ÀÌ°¡ Æ÷ÇԵǾî ÀÖ´Ù.
  • Message´Â ¿©·¯ °³ÀÇ ¿¤¸®¸ÕÆ®·Î ±¸¼ºµÈ JXTA ¸Þ½ÃÁöÀÌ´Ù. Message´Â ±×·¯ÇÑ ¿¤¸®¸ÕÆ®¿¡ ¾×¼¼½ºÇϱâ À§ÇØ ¸Þ¼Òµå¸¦ Á¦°øÇÑ´Ù.
  • PeerNetwork´Â °¡Àå À¯¿ëÇÑ Å¬·¡½ºÀÌ´Ù. JXTA ŽºÅ©¸¦ ¼³Á¤ÇÏ¿© ¸ð¹ÙÀÏ ÇǾ ¸±·¹À̸¦ ÅëÇØ ¼öÇàµÉ ¼ö ÀÖ°Ô ÇÑ´Ù. ´ÙÀ½Àº PeerNetwork Ŭ·¡½ºÀÇ À¯¿ëÇÑ ¸Þ¼ÒµåµéÀÌ´Ù:

    • createInstance()´Â ÁöÁ¤µÈ ÇǾî À̸§À» °¡Áø PeerNetworkÀÇ ÀνºÅϽº¸¦ ¸®ÅÏÇÏ´Â ÆÑÅ丮 ¸Þ¼ÒµåÀÌ´Ù.
    • connect() ¸Þ¼Òµå´Â ÁöÁ¤µÈ HTTP URL¿¡¼­ ¸±·¹ÀÌ·Î ¿¬°áÇÑ´Ù. ¿µ¼Ó »óÅ Á¤º¸ÀÇ ¹ÙÀÌÆ® ¾î·¹À̸¦ ¸®ÅÏÇÑ´Ù.
    • create() ¸Þ¼Òµå´Â ¸±·¹ÀÌ ÇÁ·Ï½Ã¸¦ ÅëÇØ JXTA ³×Æ®¿öÅ© »ó¿¡ ÇǾî, ±×·ì, ÆÄÀÌÇÁ¸¦ ¸¸µç´Ù.
    • search() ¸Þ¼Òµå´Â ÇǾî, ±×·ì, ÆÄÀÌÇÁ¸¦ °Ë»öÇÑ´Ù.
    • poll() ¸Þ¼Òµå´Â ÀÌ ¸ð¹ÙÀÏ ÇǾ Á¢±ÙÇÏ´Â ¸Þ½ÃÁö¿ë ¸ðµç ¸±·¹À̵éÀ» µî·ÏÇÑ´Ù. ¼­¹ö ¾²·¹µå¿¡¼­ ¹Ýº¹ÀûÀ¸·Î È£Ãâ µÉ ¼ö ÀÖ´Ù.
    • listen()°ú close() ¸Þ¼Òµå´Â ÀÎDz ÆÄÀÌÇÁ¸¦ ¿­°í ´Ý´Â´Ù.
    • send() ¸Þ¼Òµå´Â ¸Þ½ÃÁö¸¦ ÁöÁ¤µÈ ÆÄÀÌÇÁ¿¡ º¸³½´Ù.

±×¸² 2. net.jxta.j2me ÆÐÅ°ÁöÀÇ Å¬·¡½º
Package net.jxta.j2me classes

¿¹Á¦
JXME À¥ »çÀÌÆ®ÀÇ JXME ¼Ò½º ÄÚµå ÆÐÅ°Áö¿¡ Æ÷ÇÔµÈ mySend.java Æ©Å丮¾ó ¿¹Á¦¸¦ »ç¿ëÇÏ¿© ¾Õ¼­ ¼³¸íÇÑ API »ç¿ë¹ýÀ» ¼³¸íÇÏ°Ú´Ù. JXME ÆÐÅ°Áö´Â Project JXTA¿¡ ´ëÇÑ °³º°Àû ±â¿©µé·Î ÀÌ·ç¾îÁ® ÀÖ´Ù. ¼Ò½º ÄÚµå´Â Sun Project JXTA Software LicenseÀÇ Çã°¡¸¦ ¹Þ¾Ò´Ù.

J2ME ¿¡¹Ä·¹ÀÌÅÍ¿¡¼­ ½ÇÇàµÇ´Â ¿¹Á¦ ¸ð¹ÙÀÏ ÇǾî´Â 9700 Æ÷Æ®ÀÇ È£½ºÆ® PC(localhost) »ó¿¡¼­ ½ÇÇàµÇ´Â JXME ¸±·¹À̸¦ ÅëÇØ ¸¹Àº ¾×¼ÇµéÀ» ¼öÇàÇÑ´Ù. ¹°·Ð ½ÇÁ¦ Àü°³½Ã¿¡´Â ¸ð¹ÙÀÏ ÇǾî´Â ¸ð¹ÙÀÏ µð¹ÙÀ̽º»ó¿¡¼­ ½ÇÇàµÉ ¼ö ÀÖÀ¸¸ç localhost¸¦ ÀÚ½ÅÀÇ ¸±·¹ÀÌ ÄÄÇ»ÅÍÀÇ IP ¾îµå·¹½º·Î ¹Ù²Ü ¼ö ÀÖ´Ù. JXME ¸±·¹ÀÌ´Â ´Ù¿î·Îµå ÆÐÅ°Áö¿¡ Æ÷ÇԵǾî ÀÖ´Ù.

¿¹Á¦ ÇǾî´Â ´ÙÀ½ ´Ü°è¸¦ °ÅÄ£´Ù:

  1. »õ·Î¿î ÆÄÀÌÇÁ¸¦ ¸¸µç´Ù.
  2. ¼³Ä¡µÈ ÆÄÀÌÇÁ¸¦ ã´Â´Ù.
  3. ±× ÆÄÀÌÇÁ¸¦ ÅëÇØ ¸Þ½ÃÁö¸¦ º¸³½´Ù.
  4. ¸Þ½ÃÁö¸¦ ¹Þ´Â´Ù.

Listing 1Àº peer.listen() ¸Þ¼Òµå°¡ ¸±·¹ÀÌ¿¡°Ô »õ·Î¿î ÆÄÀÌÇÁ¸¦ ¸¸µé°ÍÀ» ¸í·ÉÇÏ°í ÀÖ´Ù.

Listing 1. »õ·Î¿î ÆÄÀÌÇÁ ±¸ÇöÇϱâ


// Create a peer and have it connect to the relay.
// A connection to relay is required before any other
// operations can be invoked.
String relayUrl = "http://localhost:9700/";
PeerNetwork peer = PeerNetwork.createInstance("mySendPeer");
byte [] persistentState = peer.connect(relayUrl, null);
 
// Have the peer create and open a Unicast pipe; PipeID will
// be returned asynchronously in a response message
int listenQueryId = peer.listen("myPipe", null, PeerNetwork.UNICAST_PIPE);
 
// Have peer search for this Pipe and then send it a Message
String pipeID = findMyPipe();
sendMyMessage(pipeID);
 
// Finally, have the peer poll for Messages sent to it
recvMessage();
}

ÆÄÀÌÇÁ ¸¸µé±â°¡ ¼º°øÇÏ¸é ¸±·¹ÀÌ´Â ¹ÙÀ̳ʸ® ¸Þ½ÃÁö¸¦ ¸ð¹ÙÀÏ ÇǾ ¸¸µç´Ù. findMyPipe() ¸Þ¼Òµå´Â ¼º°øÀ» ³ªÅ¸³»´Â ¸Þ½ÃÁö¸¦ ¹ÞÀ» ¶§ ±îÁö ·çÇÁ ¾È¿¡¼­ ¸±·¹À̸¦ µî·ÏÇÑ´Ù. ±×·± ´ÙÀ½ ¸Þ½ÃÁö¸¦ ÆĽÌÇÏ°í ÆÄÀÌÇÁ ID¸¦ ¾ò´Â´Ù. ¹ÙÀ̳ʸ® ¸Þ½ÃÁö´Â XML °°Àº ±¸Á¶¸¦ °®°íÀÖ´Ù. (Listing 2).

Listing 2. Getting the pipe we just created


public String findMyPipe() throws IOException {
  // Now poll for all messages addressed to us. Stop when we
  // find the response to our listen command
  int rid = -1;
  String id = null;
  String type = null;
  String name = null;
  String arg = null;
  String response = null;
 
  Message msg = null;
  while (true) {
    // do not use a timeout of 0, 0 means block forever
    msg = peer.poll(1);
    if (msg == null) {
      continue;
    }
    // look for a response to our search query
    for (int i = 0; i < msg.getElementCount(); i++ ) {
      Element e = msg.getElement(i);
      if (Message.PROXY_NAME_SPACE.equals(e.getNameSpace())) {
        String elementName = e.getName();
        if (Message.REQUESTID_TAG.equals(elementName)) {
          String rids = new String(e.getData());
          try {
            rid = Integer.parseInt(rids);
          } catch (NumberFormatException nfx) {
            System.err.println("Recvd invalid " +
                               Message.REQUESTID_TAG +
                               ": " + rids);
            continue;
          }
        } else if (Message.TYPE_TAG.equals(elementName)) {
          type = new String(e.getData());
        } else if (Message.NAME_TAG.equals(elementName)) {
          name = new String(e.getData());
        } else if (Message.ARG_TAG.equals(elementName)) {
          arg = new String(e.getData());
        } else if (Message.ID_TAG.equals(elementName)) {
          id = new String(e.getData());
        } else if (Message.RESPONSE_TAG.equals(elementName)) {
          response = new String(e.getData());
        }
      }
    }
    // PIPE_NAME: myPipe
    // PIPE_TYPE: PeerNetwork.UNICAST_PIPE
    if (rid == listenQueryId &&
        response.equals("success") &&
        type.equals("PIPE") &&
        name.equals(PIPE_NAME) &&
        arg.equals(PIPE_TYPE)) {
      return id;
    }
  }
}

sendMyMessage() ¸Þ¼Òµå´Â findMyPipe() ¸Þ¼Òµå¿¡¼­ ¸®ÅÏµÈ ÆÄÀÌÇÁ ID¸¦ °®°í ÆÄÀÌÇÁ¸¦ ÅëÇØ ¸Þ½ÃÁö¸¦ º¸³½´Ù. (Listing 3).

Listing 3. ÆÄÀÌÇÁ¸¦ ÅëÇØ ¸Þ½ÃÁö º¸³»±â


public void sendMyMessage(String pipeID)
    throws IOException {
  Element[] elm = new Element[2];
  // Our Message will contain two elements. Receiver should look for
  // elements with the same names ("mySend:Name" and "mySend:Message")
  // PEER_NAME: mySendPeer
  elm[0] = new Element("mySend:Name", PEER_NAME.getBytes(),
                       null, null);
  elm[1] = new Element("mySend:Message", "Hello there".getBytes(),
                       null, null);
  Message msg = new Message(elm);
  // PIPE_NAME: myPipe
  // PIPE_TYPE: PeerNetwork.UNICAST_PIPE
  sendRequestId = peer.send(PIPE_NAME, pipeID, PIPE_TYPE, msg);
  System.out.println("send request id: " + sendRequestId);
}

mySendPeer´Â ÆÄÀÌÇÁ¸¦ ¸®½º´×ÇÏ°í ÀÖ´Ù. µû¶ó¼­ ¿ì¸®°¡ º¸³½ ¸Þ½ÃÁö´Â ¸±·¹ÀÌ¿¡¼­ ¿Â °°Àº ¸ð¹ÙÀÏ¿¡ »ç¿ëÇÒ ¼ö ÀÖ´Ù. recvMessage() ¸Þ¼Òµå´Â ÀÌ ¸Þ½ÃÁö¸¦ ¹ÞÀ» ¶§ ±îÁö ¸±·¹À̸¦ µî·ÏÇÏ°í ¹ÞÀ¸¸é ÀÌ ¸Þ½ÃÁö¸¦ µð½ºÇ÷¹ÀÌÇÑ´Ù. (Listing 4).

Listing 4. ¸Þ½ÃÁö ¹Þ±â


public void recvMessage() throws IOException {
  Message msg = null;
  while (true) {
    msg = peer.poll(1);
    if (msg == null) {
      continue;
    }
    for (int i = 0; i < msg.getElementCount(); i++) {
      Element e = msg.getElement(i);
      if ("mySend".equals(e.getNameSpace()) &&
          "Name".equals(e.getName()))
        System.out.println("Message from: " +
                           new String(e.getData()));
      if ("mySend".equals(e.getNameSpace()) &&
          "Message".equals(e.getName()))
        System.out.println("Message: " +
                           new String(e.getData()));
    }
  }
}

Jabber ÀνºÅÏÆ® ¸Þ½ÅÀú
P2P ½Ã½ºÅÛÀÇ ¼º°øÀº »ç¿ëÀÚ¸¦ ²ø¾îµéÀÌ´Â ´É·Â¿¡ ´Þ·ÁÀÖ´Ù. JXTA°¡ ¸Å¿ì °­·ÂÇÏ°í ±â¼úÀûÀ¸·Îµµ ¾Õ¼± ÇÁ·¹ÀÓ¿÷ÀÌÁö¸¸ º¹À⼺ ¶§¹®¿¡ äÅÃÀ» ¸Á¼³ÀÌ°í ÀÖ´Ù. Jabber´Â JXTA º¸´Ù ÈξÀ ´Ü¼øÇÑ P2P ½Ã½ºÅÛÀÌ´Ù. ÁÖ·Î ÀνºÅÏÆ® ¸Þ½ÃÁö ±³È¯¿ëÀ¸·Î ¼³°èµÇ¾ú´Ù. Jabber´Â JXTA º¸´Ù ³ÐÀº ÇÇ¾î ³×Æ®¿öÅ©¸¦ °®°í ÀÖ´Ù.

Jabber´Â ¿ø·¡ ´ëÁßÀûÀÎ ÀÎÅÍ³Ý ÀνºÅÏÆ® ¸Þ½Ã¡ ½Ã½ºÅÛ(AOL, MSN, Yahoo!, ICQ)°£ »óÈ£ ¿î¿ë¼ºÀ» Á¦°øÇÒ ¸ñÀûÀ¸·Î ¼³°èµÇ¾ú´Ù. ¸ðµç ±âÁ¸ÀÇ IM ÇÁ·ÎÅäÄÝÀ» ·¡ÇÎÇÒ ¼ö ÀÖ´Â °­·ÂÇÏ°í À¯¿¬Çϸ鼭µµ ´Ü¼øÇÑ ÇÁ·ÎÅäÄÝÀÌ´Ù. °­·ÂÇÑ ±â´É°ú ¿ÏÀüÈ÷ °³¹æµÈ XML ÇÁ·ÎÅäÄÝÀ̶ó´Â Á¡ ¿Ü¿¡µµ Jabber´Â °¡Àå Áøº¸µÈ IM ½Ã½ºÅÛÀÌ´Ù. Jabber´Â °í±Þ P2P ¾ÖÇø®ÄÉÀ̼ÇÀ» Áö¿øÇÑ´Ù.

Jabber ÇǾîµéÀº Jabber ¼­¹öµéÀ» ÅëÇØ ¼­·Î ¼­·Î Åë½ÅÇÑ´Ù. Jabber ¼­¹ö´Â »óÈ£ Åë½ÅÇÏ¿© ÇǾîµéÀÇ Å« µµ¸ÞÀÎÀ» Çü¼ºÇÑ´Ù. ÀÌ°ÍÀº °°Àº ¼­¹ö·Î´Â Á÷Á¢ ¿¬°áµÇÁö ¾Ê´Â´Ù. Jabber ÇǾî¿Í ¼­¹ö °£ ¸ðµç Åë½ÅÀº °³¹æ XML Æ÷¸ËÀÇ ¸Þ½ÃÁö ÇüŸ¦ ÃëÇÑ´Ù. °á°úÀûÀ¸·Î Jabber ¼­¹ö¿Í ÇǾî´Â Ç÷§Æû°ú´Â µ¶¸³ÀûÀ¸·Î ±¸ÇöµÈ´Ù. Jabber °³¹ß ¶óÀ̺귯¸®´Â ÀÚ¹Ù, C++, C#, Perl, Python, PHP, Flash¿¡¼­µµ °¡´ÉÇÏ´Ù.

J2ME µð¹ÙÀ̽º(ƯÈ÷, MIDP µð¹ÙÀ̽º)¿ë Jabber Ŭ¶óÀ̾ðÆ® °³¹ßÀº ½¬¿îÀÏÀÌ ¾Æ´Ï´Ù. ¸ðµç MIDP Jabber Ŭ¶óÀ̾ðÆ®´Â XML Æļ­°¡ ÀÖ¾î¾ßÇÑ´Ù. °Ô´Ù°¡ MIDP VM°ú ±âÀú ³×Æ®¿öÅ©°¡ ¿ø½Ã ¼ÒÄÏ ¿¬°áÀ» Áö¿øÇØ¾ß ÇÑ´Ù. MIDP 1.0 ȣȯÀÇ Jabber Ŭ¶óÀ̾ðÆ® ¶Ç´Â ¶óÀ̺귯¸®°¡ ¸¹ÀÌ ÀÖ´Ù:

  • Al SuttonÀÇ KVMJabÀº MIDP Ç÷§ÆûÀ» À§ÇÑ ¿ÀÇ ¼Ò½º Jabber ¶óÀ̺귯¸®ÀÌ´Ù. MIDP Jabber ¾ÖÇø®ÄÉÀÌ¼Ç °³¹ß¿¡ ÇÊ¿äÇÑ °£´ÜÇÑ API¸¦ Á¦°øÇÑ´Ù.
  • uppliÀÇ uMessenger´Â ¿Ïº®ÇÑ ±â´ÉÀÇ Jabber IM Ŭ¶óÀ̾ðÆ® ÀÌ´Ù. ÆÄÀÏ °øÀ¯¸¦ Áö¿øÇÑ´Ù.

Âü°íÀÚ·á

¸ñ Â÷:
¸ð¹ÙÀÏ ÀåÄ¡¿ë JXTA
JXME API
±×¸² 2. net.jxta.j2me ÆÐÅ°ÁöÀÇ Å¬·¡½º
¿¹Á¦
Âü°í ÀÚ·á
ÇÊÀÚ ¼Ò°³
±â»ç¿¡ ´ëÇÑ Æò°¡
°ü·Ã dW ¸µÅ©:
Mobile P2P messaging, Part 1
The JXTA story
The JXTA command shell
Creating JXTA systems
Subscribe to the developerWorks newsletter
US ¿ø¹® Àбâ
Also in the Java zone:
Tutorials
Tools and products
Code and components
Articles
ÇÊÀÚ¼Ò°³
Michael J. Yuan: ¿¬±¸¿ø(University of Texas at Austin, ÀüÀÚ»ó°Å·¡ ¼¾ÅÍ).
ÀÌ ±â»ç¿¡ ´ëÇÏ¿© ¾î¶»°Ô »ý°¢ÇϽʴϱî?

Á¤¸» ÁÁ´Ù (5) ÁÁ´Ù (4) ±×Àú±×·¸´Ù (3) ¼öÁ¤º¸¿ÏÀÌ ÇÊ¿äÇÏ´Ù(2) ÇüÆí¾ø´Ù (1)

  È¸»ç¼Ò°³  |  °³ÀÎÁ¤º¸ º¸È£Á¤Ã¥  |  ¹ý·ü  |  ¹®ÀÇ