服务端类 ChatServerThread
import java.net.Socket;
public class ChatServerThread {
public static void main(String[] args) throws Exception {
Socket socket = new Socket(“127.0.0.1”, 8888);
SendImpl sendImpl = new SendImpl(socket);
// 发送的线程
new Thread(sendImpl).start();
// 接收的线程
ReciveImpl reciveImpl = new ReciveImpl(socket);
new Thread(reciveImpl).start();
}
}
客户端类 ChatClientThread
import java.net.ServerSocket;
import java.net.Socket;
public class ChatClientThread {
public static void main(String[] args) throws Exception {
ServerSocket serverSocket = new ServerSocket(8888);
Socket socket = serverSocket.accept();
SendImpl sendImpl = new SendImpl(socket);
new Thread(sendImpl).start();
ReciveImpl reciveImpl = new ReciveImpl(socket);
new Thread(reciveImpl).start();
}
}
发送类 SendImpl
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;
public class SendImpl implements Runnable {
private Socket socket;
public SendImpl(Socket socket) {
this.socket = socket;
}
@Override
public void run() {
Scanner scanner = new Scanner(System.in);
while (true) {
try {
OutputStream outputStream = socket.getOutputStream();
String string = scanner.nextLine();
outputStream.write(string.getBytes());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
接收类 ReceiveImpl
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
总结
谈到面试,其实说白了就是刷题刷题刷题,天天作死的刷。。。。。
为了准备这个“金三银四”的春招,狂刷一个月的题,狂补超多的漏洞知识,像这次美团面试问的算法、数据库、Redis、设计模式等这些题目都是我刷到过的
并且我也将自己刷的题全部整理成了PDF或者Word文档(含详细答案解析)
66个Java面试知识点
架构专题(MySQL,Java,Redis,线程,并发,设计模式,Nginx,Linux,框架,微服务等)+大厂面试题详解(百度,阿里,腾讯,华为,迅雷,网易,中兴,北京中软等)
算法刷题(PDF)
dis,线程,并发,设计模式,Nginx,Linux,框架,微服务等)+大厂面试题详解(百度,阿里,腾讯,华为,迅雷,网易,中兴,北京中软等)**
[外链图片转存中…(img-0QPoE8LM-1720126204610)]
算法刷题(PDF)
[外链图片转存中…(img-zQtES1JN-1720126204611)]