package com.wenqier.service; import java.net.*; import java.io.*; //聊天过程中新建一个专门用于发送信息的线程 class Send extends Thread { Socket socket; public Send(Socket sock) { this.socket = sock; } // 专门用于发送信息 public void run() { DataOutputStream out; while (true) { BufferedReader input = new BufferedReader(new InputStreamReader( System.in)); try { String str; str = input.readLine(); out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(str); } catch (Exception e) { } } } } // 创建一个专门用于接收消息的线程 class Receive extends Thread { Socket socket; public Receive(Socket sock) { this.socket = sock; } public void run() { // 专门用于接收消息 DataInputStream in; while (true) { try { in = new DataInputStream(socket.getInputStream()); String str = in.readUTF(); System.out.println(str); } catch (Exception e) { } } } } public class Service { // 声明ServerSocket类对象 static ServerSocket service; public static void main(String[] args) { try { service = new ServerSocket(5678); System.out.println("服务器端....."); Socket client = null; client = service.accept(); Send send = new Send(client); Receive receive = new Receive(client); // 打开线程 send.start(); receive.start(); } catch (Exception e) { } } }

lszc123 LV1
2022年5月24日
xingbing LV9
2022年1月28日
tangjj7260 LV18
2021年12月10日
kanwobiaoyan LV1
2021年11月21日
wxk666 LV2
2021年9月23日
Jsofe.柒间 LV1
2021年7月21日
1690356080 LV38
2021年6月26日
ssss沈 LV1
2021年6月16日
小白小怪 LV10
2021年6月8日

28128觅北 LV2
2024年5月22日
krispeng LV14
2024年4月17日
陈小灏 LV18
2023年12月26日
fuyouou LV5
2023年6月29日
2017143155 LV12
2023年6月24日
didnxjdjfhdk
2023年6月20日
暂无贡献等级
adminadminsqwqe LV8
2023年5月11日
人工智能4708 LV11
2023年5月8日
臧家旺 LV3
2023年4月27日
ewan007 LV30
2023年4月21日