Java本科专业教程
2. Java的基本输入输出流有哪些? 主要的功能如何?
3#. 利用基本输入输出流编写程序:从键盘输入一串字符,然后显示到屏幕上。
第十四章 Java网络编程
1. 套接字概念
2. TCP方式传接数据
3. UDP方式传接数据
看懂下面的程序:
import http://www.77cn.com.cn.*;
import java.util.Date;
import java.io.*;
public class TestSocket {
public static void main(String[] args) throws Exception {
new Server().start();
Thread.sleep(2000);
new Client().start();
Thread.sleep(2000);
Server.stopMe = true;
}
}
class Server extends Thread {
public static final int PORT = 44442;
public static boolean stopMe = false;
public void run() {
ServerSocket ss = null;
try {
ss = new ServerSocket(PORT);
while (!stopMe) {
Socket client = ss.accept();
new ServerWorker(client).start();
}
} catch (IOException e) {
} finally {
try {
ss.close();
} catch (Exception e) {
}
}
}
}
class ServerWorker extends Thread {
private Socket clientReq = null;
private OutputStream out = null;
private OutputStreamWriter w = null;
private PrintWriter pw = null;
public ServerWorker(Socket clientReq) {
this.clientReq = clientReq;
}