皮皮学,免费搜题
登录
logo - 刷刷题
搜题
【简答题】
有下面一段Server段程序,目的是能够同时服务多个客户,客户的请求是一句话(一个 String)。如果这个请求的内容是字符串"plain"的话,服务器仅将"hello"字符串返回给用户。否则将用户的话追加到当前目录的文本文件Memo.txt中(路径为"Memo.txt"),并向用户返回"OK"。注意Server并发的处理多用户,Memo.txt被共享,要求不能出现数据不一致。Server的程序如下文件Server.java: public class Server{ public static void main(String args[]){ MemoController memoController = new MemoController(); try{ ServerSocket ss = new ServerSocket(1999); while (true){ Socket s = ss.accept(); try{ UserThread t = new UserThread(s, memoController); t.start(); }catch(Exception e){ e.printStackTrace(); } } }catch(Exception e){ e.printStackTrace(); }finally{ memoController.close(); } } } 类UserThread程序如下: 文件UserThread.java: public class UserThread extends Thread{ Socket s; MemoController memo; public UserThread (Socket s, MemoController memo){ this.s = s; this.memo = memo; } public void run(){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); String req = br.readLine(); if (req.equals("plain")){ pw.println("hello"); }else{ memo.append(req); pw.println("OK"); } pw.flush(); pw.close(); br.close(); s.close(); }catch(Exception e){ e.printStackTrace(); } } } 请根据题目的要求和现有的Server.java, UserThread.java的程序完成类MemoController.java的程序。
手机使用
分享
复制链接
新浪微博
分享QQ
微信扫一扫
微信内点击右上角“…”即可分享
反馈
参考答案:
举一反三
【简答题】下面程序段的运行结果是()。 INTEGER FNF FNF(X,Y)=X/Y+X A=-2.0 B=4.0 B=I.0+FNF(A,B) WRITE(*,′(F5.1)′)B END (A) -1.0 (B) 0.0 (C) 1.0 (D) 2.0
【单选题】Directions: Replace the underlined part in each of the following sentences with a word or phrase from the choices below. 1. The research team has made all necessary preparations for the project to sta...
A.
underwent
B.
adored
C.
postponed
D.
put on
【简答题】优质价廉的商品令万众瞩目。 ( focus attention on/ commodities/ quality/ price )
【单选题】The first Olympic flag was made at the Olympic birthplaces Athens, Greece.
A.
Y
B.
N
C.
NG
【单选题】Directions: Replace the underlined part in each of the following sentences with a word or phrase from the choices below. 1 All electronic computers are made up of four basic units although they may b...
A.
in use
B.
in addition
C.
consist of
D.
put in
【单选题】下列语句组中,正确的是
A.
char*s;s="Olympic";
B.
char s[7];s="Olympic";
C.
char*s;s={"Olympic"};
D.
char s[7];s={"Olympic"};
【判断题】企业采用服务差别化的市场定位战略,就可以不用再追求技术和质量的提高。
A.
正确
B.
错误
【简答题】Directions: Replace the underlined part in each of the following sentences with a word or phrase from the box below. Change the form where necessary. She had no liking for aimlessness, and besides tho...
【判断题】企业采用服务差别化的市场定位战略,就可以不再追求技术和质量的提高。(    )
A.
正确
B.
错误
【单选题】下面程序段的运行结果是( )。 INTEGER FNF FNF(X,Y)=X/Y+X A=-2.0 B=4.0 B=I.0+FNF(A,B) WRITE(*,′(F5.1)′)B END
A.
-1.0
B.
0.0
C.
1.0
D.
2.0
相关题目:
参考解析:
知识点:
题目纠错 0
发布
创建自己的小题库 - 刷刷题