当前位置:编程学习 > JAVA >>

高分求解一个socket笔试题

1.  
有一个模块,有如下需求:

a) 和外部系统通过socket连接,外部系统为server,模块为client。

b) 模块与外部系统通过socket进行"模块->外部系统"的单向命令发送,命令模式为"请求->响应",命令是同步的,在一个socket中,前一个命令没有执行完前,不允许发送第二个命令。 

c) 模块可以和一个外部系统建立多个连接,一个外部系统的多个连接之间采用负载平衡。 

d) 模块可以同时连接两个外部系统,两个外部系统之间采用主备方式。 

e) 模块需要增加统计功能,要能统计与一个外部系统的所有连接的消息总数。 

i. 模块需要增加监控功能,要能在线跟踪与所有外部系统发送的请求和接收的响应。 

要求: 

1) 请设计此模块,写出出主要的类和接口。类不要求细化到方法级,但要能说明接口和类之间的关系和每个类/接口的主要职能。 

2) 从模块调用者角度,写出如何实例化1中相关的类,如何调用。 

3) 要求设计时要考虑系统的灵活性、可扩展性和可维护性。鼓励采用适当的设计模式,并请说明你使用的设计模式以及简单说明使用这些模式的目的。 --------------------编程问答-------------------- UP!!
我表示鸭梨很大 --------------------编程问答-------------------- 你这笔试给你多长时间啊,从d)以下的要求不是短时间能完成的。 --------------------编程问答-------------------- 这个可以做个项目出来了 --------------------编程问答-------------------- 笔试题做这个,压力真心大啊。。 --------------------编程问答-------------------- 这是笔试还是作业啊,。。。。。。。 --------------------编程问答-------------------- Vector<ServerThread_2> m_threads;
Socket m_socket = null;
DataInputStream m_in = null;
DataOutputStream m_out = null;
InputStream m_in_in = null;
String m_nid;

/**
 * 
 */
public ServerThread_2(Socket s, Vector<ServerThread_2> threads) {
// TODO Auto-generated constructor stub
m_socket = s;
m_threads = threads;
try {
m_in = new DataInputStream(m_socket.getInputStream());
// m_out = new DataOutputStream(m_socket.getOutputStream());
m_in_in = m_socket.getInputStream();
} catch (Exception e) {

}
}

public void run() {
BufferedReader br = null;
InputStreamReader fr = null;
try {
// while(true){
// while(m_in!=null&&m_in.read()!=-1){
fr = new InputStreamReader(m_in);
br = new BufferedReader(fr);
String temp1 = null;
StringBuffer sb1 = new StringBuffer();
// if(br.readLine().contains("017200037")){
// System.out.println("br.readLine()====="+br.readLine());
// }
while ((temp1 = br.readLine()) != null) {

sb1.append(temp1);
System.out.println("sb1====" + temp1);
if (temp1.toString().equals("bye") || temp1.equals("ye")
|| temp1 == null) {
// System.out.println("out from socket"+temp1);
return;
}
// if(!temp1.contains("-")){
insertIntoDatabase(temp1.split("&"));
// }
}
// System.out.println("all =================="+i);
// System.out.println("sb1===="+sb1.toString());
// }
}

// }
catch (Exception e) {
e.printStackTrace();
} finally {

try {
if (br != null) {
br.close();
}
if (fr != null) {
fr.close();
}
m_threads.removeElement(this);
System.out.println(" 总线程数 = " + m_threads.size());
m_socket.close();
} catch (Exception e) {

}
}
} --------------------编程问答-------------------- 正好在做这样的东东,顺便贴贴代码 --------------------编程问答-------------------- 链接方式

数据接口格式

代码设计实现

还要有负载均衡和主备替换

这是面试题?

你把这都做了,人家也不要你,一个组小半年的活让你做完了

还要你干嘛? --------------------编程问答-------------------- 这样的笔试题,对面试者压力很大~~ --------------------编程问答-------------------- 呵呵,鸭梨山大呀。
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,