[原] Unity下的ElectroServer的连接

ES的版本是5.4.1,示例目录下code_examples\ConnectAndLoginManually是Unity的连接和登录代码。

除了host和port需要指定,在连接时需要指定连接方式,如下第10行指定了BinaryTCP。

 1 void Start () {
 2     log4net.Config.BasicConfigurator.Configure();
 3     
 4     es.Engine.Queueing = EsEngine.QueueDispatchType.External;
 5 
 6     es.Engine.ConnectionResponse += OnConnectionResponse;
 7     es.Engine.LoginResponse += OnLoginResponse;
 8 
 9     Server server = new Server("server1");
10     AvailableConnection availCon = new AvailableConnection(host, port, AvailableConnection.TransportType.BinaryTCP);
11     server.AddAvailableConnection(availCon);
12 
13     es.Engine.AddServer(server);
14 
15     Security.PrefetchSocketPolicy(host, port);
16 
17     es.Engine.Connect();
18 }

其它可选项是:

AvailableConnection.TransportType.BinaryHTTP
AvailableConnection.TransportType.BinaryTCP
AvailableConnection.TransportType.BinaryUDP

连接方式对应的端口在AdminTool的Server Management中定义。 如下配置中,如果使用BinaryTCP,端口号是9898。

posted @ 2013-12-31 17:05  BaseCN  阅读(301)  评论(0编辑  收藏  举报