不断向客户端发送不同类型的有意义的xml数据,模拟生产系统的不同状态。考虑到功能的简便性,服务端只是每2秒向客户端发送一条随机类型的数据,而没有包括模拟生产系统及时的状态,如在某一时刻发生错误时,发送一条表示错误类型的数据,在实际设计编程中,基于本文中的例子,可以轻松扩展实现所需功能。
public void run() {
try {
while (true) {
system.out.println(this.getname() + "------" + i++);
d = new date();
if(new random().nextint()*100 < 50){
str = "< message type=\"error\" text=\"hello, my name is morgan!\" time=\"" + d.tostring() + "\"/>";
} else {
str = "
}
byte[] s= str.getbytes();
out.write(s);
out.write(0);
out.flush();
this.sleep(2000);
}
} catch (exception ex){
ex.printstacktrace();
}
}
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器