java - 我试图创建一个在java中发送和接收消息的线程但是我不确定如何解决显示的错误消息
问题描述
我试图通过创建一个允许客户端发送和接收消息的新线程来创建多线程连接。我面临的问题是我的代码中显示的所有错误,我不确定从哪里开始以及如何建立此代码以进行实际连接。感谢任何遇到并提供帮助的人。
打包发送消息;
线程 SendMessage = 新线程(新 Runnable(){
@Override
public void run() {
while (true) {
// read the message to deliver.
String msg = sc.nextLine();
try {
// write on the output stream
dos.writeUTF(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
包读消息;
线程 ReadMessage = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
// read the message sent to this client
String msg = dis.readUTF();
System.out.println(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
解决方案
推荐阅读
- amazon-web-services - AWS VPC - 无法从私有子网中的堡垒主机通过 SSH 连接到不同子网中同一 VPC 中的 EC2 实例
- python - Scrapy KeyError:'Spider not found',但在终端中执行'scrapy list'时存在蜘蛛
- excel - Visual Basic 不保存工作表
- excel - 数据验证 - 您只能在列中写入两次相同的值
- c - 解压 16 位 BCD 的最有效公式?(例如 0x1234 到 0x01020304)
- mlr - MLR中是否有任何功能可以制作复杂的学习者
- twilio - 使用 SMS MFA (Twilio) 扩展 E2E 测试的方法
- google-cloud-platform - Google Cloud Resource Manager - 在文件夹中创建项目
- c++ - 如何将鼠标坐标转换为“mm”
- r - 更改图例标题 ggplot