Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Socket	
  Programming	
  Projects	
  
CISC	
  650/450	
  Computer	
  Networks	
  
Fall	
  2010	
  
Instructor:	
  Chien-­‐chung	
  Shen	
  
TA:	
  Yang	
  Guan	
  
MulH-­‐Threaded	
  Web	
  Server	
  
MulH-­‐Threaded	
  Web	
  Server	
  
•  Developing	
  a	
  web	
  server	
  capable	
  of	
  serving	
  
mulHple	
  requests	
  in	
  parallel	
  
•  Implement	
  HTTP	
  version	
  1.0	
  
•  A	
  separate	
  TCP	
  connecHon	
  is	
  created	
  for	
  each	
  
request/response	
  pair	
  
•  A	
  main	
  thread	
  that	
  listens	
  on	
  the	
  port,	
  waiHng	
  
for	
  incoming	
  requests	
  
•  Each	
  Hme	
  a	
  request	
  comes,	
  a	
  new	
  thread	
  is	
  
created	
  to	
  process	
  the	
  request	
  
MulH-­‐Threaded	
  Web	
  Server	
  
•  Request	
  messages	
  
– GET	
  
•  Response	
  messages	
  
– 200	
  OK	
  
– 400	
  Bad	
  request	
  
– 404	
  Not	
  Found	
  
MulH-­‐Threaded	
  Web	
  Server	
  
•  Use	
  port	
  number	
  larger	
  than	
  1024,	
  instead	
  of	
  80	
  
•  Access	
  your	
  server	
  by	
  typing:	
  
–  h[p://sHmpy.eecis.udel.edu:5678/dir/index.html	
  
•  Test	
  your	
  server	
  with	
  mulHple	
  web	
  browsers	
  
•  Develop	
  your	
  code	
  on	
  EECIS	
  machines	
  
•  Use	
  any	
  language	
  you	
  like	
  (C,	
  C++,	
  JAVA)	
  
•  Submit	
  a	
  Makefile	
  with	
  your	
  code	
  
Network	
  Jeopardy	
  Protocol	
  
Network	
  Jeopardy	
  Protocol	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(Collect_subscripHon)	
  
Client	
  1	
  
CM_SUBSCRIBE	
  
Client	
  2	
  
CM_SUBSCRIBE	
  
Client	
  	
  n	
  
CM_SUBSCRIBE	
  
……	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(GAME_IN_PROGRESS)	
  
Client	
  1	
  
SM_NEW_GAME	
  
Client	
  2	
  
SM_NEW_GAME	
   SM_NEW_GAME	
  
……	
  
• 	
  Check	
  number	
  of	
  alive	
  
connecHons	
  
• 	
  Stop	
  accepHng	
  new	
  
connecHons	
  
• 	
  NoHfy	
  all	
  clients	
  
Client	
  n	
  
• 	
  Update	
  state	
  
• 	
  Display	
  all	
  clients’	
  informaHon	
  
• 	
  Display	
  categories’	
  informaHon	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(ROUND_IN_PROGRESS)	
  
Client	
  1	
  
SM_NEW_ROUND	
  
Client	
  2	
  
SM_NEW_ROUND	
  
Client	
  n	
  
SM_NEW_ROUND	
  
……	
  
•  Select	
  a	
  client	
  
•  Send	
  all	
  clients	
  	
  	
  	
  	
  
SM_NEW_ROUND	
  
message	
  
• 	
  Display	
  “WaiHng	
  for	
  Client	
  1	
  to	
  
select	
  category”	
  
• 	
  Display	
  “Please	
  select	
  a	
  
category”	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(ROUND_IN_PROGRESS)	
  
Client	
  1	
  
CM_CATEGORY	
  
Client	
  2	
   Client	
  n	
  ……	
  
•  Ensure	
  
CM_CATEGORY	
  
message	
  is	
  from	
  the	
  
selected	
  client	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(CATEGORY_SELECTED)	
  
Client	
  1	
   Client	
  2	
   Client	
  n	
  ……	
  
SM_CATEGORY	
   SM_CATEGORY	
   SM_CATEGORY	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(WAIT_FOR_RING)	
  
Client	
  1	
   Client	
  2	
   Client	
  n	
  ……	
  
SM_QUESTION	
   SM_QUESTION	
   SM_QUESTION	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(WAIT_FOR_CM_ANSWER)	
  
Client	
  1	
  
CM_RING	
  
Client	
  2	
   Client	
  n	
  ……	
  
•  How	
  to	
  resolve	
  
simultaneous	
  
CM_RING	
  messages?	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(WAIT_FOR_CM_ANSWER)	
  
Client	
  1	
   Client	
  2	
   Client	
  n	
  ……	
  
SM_RING_CLIENT	
   SM_RING_CLIENT	
   SM_RING_CLIENT	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(WAIT_FOR_CM_ANSWER)	
  
Client	
  1	
   Client	
  2	
   Client	
  n	
  ……	
  
• 	
  Typing	
  answer	
  
•  What	
  if	
  no	
  answer	
  
comes	
  from	
  the	
  
client?	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(END_OF_ROUND)	
  
Client	
  1	
  
CM_ANSWER	
  
Client	
  2	
   Client	
  n	
  ……	
  
•  Is	
  the	
  answer	
  correct?	
  
Network	
  Jeopardy	
  Protocol	
  
Game	
  Master	
  
(END_OF_ROUND)	
  
Client	
  1	
   Client	
  2	
   Client	
  n	
  ……	
  
SM_ANSWER	
   SM_ANSWER	
   SM_ANSWER	
  
Network	
  Jeopardy	
  Protocol	
  
•  A	
  new	
  round	
  is	
  started	
  aler	
  this:	
  
– Update	
  number	
  of	
  quesHons	
  in	
  each	
  categories	
  
– Who	
  is	
  the	
  next	
  one	
  to	
  select	
  categories	
  
– Score	
  board	
  
•  How	
  many	
  message	
  types?	
  
•  Define	
  your	
  message	
  format	
  carefully	
  
•  Finite	
  state	
  machine	
  for	
  game	
  master	
  and	
  
player	
  
Network	
  Jeopardy	
  Protocol	
  
•  Test	
  your	
  code	
  
– On	
  EECIS	
  machines	
  
– One	
  game	
  master,	
  at	
  least	
  two	
  players,	
  two	
  
categories,	
  two	
  quesHons	
  in	
  each	
  category	
  
•  Submit	
  your	
  code:	
  
– Contain	
  a	
  Makefile	
  telling	
  me	
  how	
  to	
  compile	
  your	
  
codes