1,网络连接
(1)用户向服务器发送请求(Socket);
(2)服务器向用户发送信息(ServerSocket),一直监听的话用.accept();
2,信息发送与接收
(1)客户向服务器端发送信息:OutputStream os = ClientSocket.getOutputStream();PrintStream ps = new PrintStream(os);封装流;
(2)服务器收到用户信息:InputStream is = client.getInputStream();BufferedReader br = new BufferedReader(new InputStreamReader(is));
(3)服务器端向客户发送信息:类似(1);
(4)客户收到服务器端信息:类似(2);
3,线程与多线程
(1)创建新的线程需要implements Runnable,线程启动需要用.start();
(2)生命周期:new,runnable,not runnable(一直监听,定期释放后,比如sleep、阻塞),dead;
(3)Thread th = Thread.currentThread();当前线程;
(4)线程创建后都会默认执行run方法;
(5)获取键盘输入:BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
时间: 2024-10-17 00:03:03