我正在开发一个基于Netty的拍卖系统。 我使用Netty,因为Google使用教会了我,NIO可以处理比普通套接字编程所能处理的更大的客户端。Netty中客户端和客户端处理器之间的通信
基本上我是Netty的首发。我已经介绍了教程和用户指南。就是这样。 因此,如果我的问题不符合“问题”的标准。 以下是我的客户端的伪代码。
public class AuctionClient
{
private boolean loggedIn;
public AuctionClient() //constructor
///
.... // various functions
///
public void run()
{
while (true)
{
int option = getUserOption(); //get user menu selection
switch(option)
{
case 1:
login(); //user enters username and password. The info is converted into JSON string and sent to AuctionServer.
//AuctionServer returns true if the info is correct, false otherwise
break;
case 2:
startAuction(); //start a new auction
break;
case 3:
makeBid(); //make a bid to an existing auction
break;
case 4:
logout(); //log out from the AuctionServer
break;
default:
break;
}
}
}
public static void main() // Creates AuctionClient class and runs it.
}
这是我想要做的事情的要点。 问题是,我只想在变量loggedIn为true的情况下启用startAuction(),makeBid()和logout()。所以我必须知道登录是否成功以更改loggedIn的值。
但由于AuctionClientHandler(虽然现在显示在此处)处理login()的结果,因此AuctionClient无法知道登录是否成功。
有没有一种优雅的方式来解决这个问题。我想避免使用BlockingQueue在AuctionClient和AuctionClientHandler之间传递信息。或者是否有更好的拍卖系统设计?
任何帮助,将不胜感激。
爱德华
正如我上面所说,我目前正在使用SynchronousQueue(不是我真正想要的,但它是在开玩笑)。你的游戏服务器代码肯定会对我有很大的帮助。现在,我使用用户标识作为关键字,将开放频道保存在HashMap中。但为会话管理保留一个单独的类似乎更加复杂。谢谢(你的)信息。 – mp2893