public class Sever { ServerSocket ss = null; public Sever() {
try {
init();
} catch (Exception e) { System.out.println(e.getMessage());
}
} void init() throws Exception {
ss = new ServerSocket(6666);
System.out.println(ss);
} void waitForClient() {
try {
while (true) {
System.out.println("Waiting for connect!");
Thread t = new Thread(new Client(ss.accept()));
t.start();
} } catch (Exception e) {
System.out.println("waitForClient ->" + e.getClass().getName()
+ ":" + e.getMessage());
} } public static void main(String[] args) {
Sever sever = new Sever();
sever.waitForClient();
}
}
try {
init();
} catch (Exception e) { System.out.println(e.getMessage());
}
} void init() throws Exception {
ss = new ServerSocket(6666);
System.out.println(ss);
} void waitForClient() {
try {
while (true) {
System.out.println("Waiting for connect!");
Thread t = new Thread(new Client(ss.accept()));
t.start();
} } catch (Exception e) {
System.out.println("waitForClient ->" + e.getClass().getName()
+ ":" + e.getMessage());
} } public static void main(String[] args) {
Sever sever = new Sever();
sever.waitForClient();
}
}
解决方案 »
- 诡异之极: springmvc中在jsp中显示List整体可以现实拿List.i就null
- 简单EJB的问题~~求人解救
- 北京奋斗了3天,终于找到工作了。散分
- Session的属性(对象)
- 高分请教:关于hibernate的奇怪问题
- 从oracle10g读取数据,不同AP服务器结果不一致。
- 小妹学编程,在线求助。。。
- 装了jbuider就意味装了j2eesdk吗??在线等!!1
- 服务器端用java的serversocket,客户端用VC写的csocket,它们之间能正常接发数据吗?
- 在JB7中无法从servlet中调用Local接口的EJB。我该怎么办?
- request.getRemoteAddr();为什么老是127.0.0.1?
- 如何取得用户从登录到关掉网页的在线时间?代码要怎么写,要写在哪里?
private BufferedReader inStream = null; private PrintWriter outStream = null; private Socket s = null; public Client(Socket socket) {
s = socket;
try {
System.out.println("Socket accepted!");
s.setSoTimeout(300000);
inStream = new BufferedReader(new InputStreamReader(s
.getInputStream()));
outStream = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(s.getOutputStream())), true); } catch (Exception e) {
} } /**
* 用户中止程序执行
*/
public void destroy() { } public void run() { try { while (true) { String str = inStream.readLine();
System.out.println("Got String :" + str);
//对内容进行处理..
}
} catch (Exception e) {
} finally {
try {
destroy();
inStream.close();
outStream.close();
s.close();
} catch (Exception e) {
} } }
}