【问题标题】:server response sets boolean true/false服务器响应设置布尔值 true/false
【发布时间】:2016-08-02 03:42:41
【问题描述】:

我现在正在使用一个程序,该程序向/从服务器发送/接收消息。

我在 ClassOne 中保护了名为 onNotice 的 void,它在服务器发出“通知”(又名消息)时从服务器获取参数:

onNotice(sourceNick, notice){}

我在 ClassTwo 中有一个方法触发 onNotice 的服务器响应:

noticeCheck(sender){
sendNotice("receiver", "sendNotice triggers server response" + sender);
}

//followed by next action
nextAction(){
if(noticeTrue){
doSomething;
return;
}
doSomethingElse;
}

如何在 ClassOne 中为 nextAction 创建 noticeTrue? nextAction 不应该等待 onNotice 收到服务器响应,然后再决定 noticeTrue 是真还是假吗?

非常感谢您的帮助

【问题讨论】:

  • 我在类的顶部添加了一个静态布尔值,将 noticeTrue 设置为 false。然后在 onNoticed 完成时将 noticeTrue 更改为 true。谢谢@Matteo!

标签: java sockets if-statement io boolean


【解决方案1】:

在noticeTrue 时赋值为false,在onNotice 时将值更改为true

【讨论】:

  • 现在试一试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 1970-01-01
相关资源
最近更新 更多