Java与ActionScript的Socket(1)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cn.vicky.socket;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Vector;
/**
*
* @author Vicky
* 广播类
*/
public class BManager extends Vector<Socket> {
/**
* 对所有已经连接上的socket发送消息
* @param msg
* @throws IOException
*/
public synchronized void sendToAll(String msg) throws IOException {
Socket socket = null;
PrintWriter writer = null;
for (int i = 0; i < size(); i++) {
socket = get(i);
if (socket != null) {
writer = new PrintWriter(socket.getOutputStream(),true);
if (writer != null) {
writer.println(msg);
}
}
}
}
/**
* 向某个人发送消息
* @param msg
* @param socket
* @throws IOException
*/
public synchronized void sendToOne(String msg, Socket socket) throws IOException {
PrintWriter writer = null;
if (socket != null && contains(socket)) {
writer = new PrintWriter(socket.getOutputStream(),true);
if (writer != null) {
writer.println(msg);
}
}
}
/**
* 向所有人发送当前在线人数
* @throws IOException
*/
public synchronized void sendInfo() throws IOException {
String msg = "当前人数:" + size() + "人";
sendToAll(msg);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cn.vicky.socket;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Vicky
* 聊天系统服务器
*/
public class ChatServer {
private static final Logger logger
相关文档:
List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1 List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......
2008 年 6 月 24 日
原文地址: http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0806wangys/
本文介绍 IBM FileNet P8 4.0 Platform 提供的 Content Java API。首先对 FileNet P8 Content Engine 和 API 进行概要介绍, 并说明了一些基本概念,随后详细介绍了 FileNet Content Engine提供的基于 EJB ......
Java
命令行工具总结
1、命令
C\Documents and Settings\Zianed>ls ‘%JAVA_HOME%’/bin
HtmlConverter.exe javap.exe jstatd.exe rmid.exe
appletviewer.exe javaw.exe &n ......
之前51CTO曾发过一篇文章叫做《OSGi为什么重要:向模块化转移的主攻手
》,里面对于OSGi的优势进行了分析。不过,对于
究竟什么是OSGi,很多人仍然只有一个模糊的概念。本系列(你好,OSGi
)从基础开
始介绍了OSGi。本部分介绍OSGi是什么,以及OSGi容器的一些现状。(注:本文英文原文于08年3月发布在JavaWorld网站)
......
java定时器的使用
定时器类Timer在java.util包中。使用时,先实例化,然后使用实例的schedule(TimerTask task, long delay)方法,设定指定的任务task在指定的延迟delay后执行。定时器任务类TimerTask是抽象类,继承并重写其run()方法,可实现具体任务。
schedule(TimerTask task, Date time)设定指定任务task在指 ......