您好,欢迎访问三七文档
ProjectDarkstar客户端开发指南TranslateBy:ChinaEstone------------------------------------------------------------------------------------------------------------------------------------------Whatwecallhumannatureisactuallyhumanhabbit.ProjectProjectProjectProjectDarkstarDarkstarDarkstarDarkstar客户端开发指南(Java版)翻译:中國壹石頭博客:邮箱:chinaestone@gmail.comestone@yeah.netProjectDarkstar客户端开发指南TranslateBy:ChinaEstone------------------------------------------------------------------------------------------------------------------------------------------Whatwecallhumannatureisactuallyhumanhabbit.Contents目录Introductionv简介Lesson1:HelloUserClient1第一课:HelloUserClientSimpleClient1简单的一个客户端----SimpleClientConnecting1连接Client/ServerCommunication2客户端/服务器通信RunningHelloUserClient3运行HelloUserClientCode:HelloUserClient3代码:HelloUserClientHelloUserClient3HelloUserClientLesson2:HelloChannelClient10第二课:HelloChannelClientPublish/SubscribeChannels10订阅/发布的通道JoiningandLeavingaChannel10加入和退出一个通道SendingandReceivingChannelMessages10发送和接收通道的信息RunningHelloChannelClient11运行HelloChannelClientCode:HelloChannelClient11代码:HelloChannelClientHelloChannelClient11HelloChannelClientConclusion15总结ProjectDarkstar客户端开发指南TranslateBy:ChinaEstone------------------------------------------------------------------------------------------------------------------------------------------Whatwecallhumannatureisactuallyhumanhabbit.Introduction介绍ThisdocumentisashorttutorialforprogrammingclientsthatconnecttotheProjectDarkstarServer(PDS).这篇文档是一个简单的用于编写和PDS系统通讯的一个客户端开发指南。ProgramminggameclientsthatuseserversprovidedbytheProjectDarkstarServerisnotmuchdifferentfromcodinganyothersortofgameclient.ThebigdifferencebetweenPDS-basedgamesandothersishowtheyconnecttoandcommunicatewiththeserverandwitheachother.Thistutorialfocusesonthe“plumbing”necessarytomakethoseconnections.使用PDS环境开发一个游戏的客户端和使用其他形式开发一个游戏客户端有很多不同的地方。基于PDS的游戏和其他的服务器最大的不同是怎样和服务器进行连接和通信,已经怎样使用客户端和服务器进行连接和通信。本指南的特点是在于讲述以“装修水管的工作方式(添加和删除通道Channel)”进行这种连接的必要性。Itdoesnotattempttoaddressthedesignissuesofhowtodesignagoodclient/serverarchitectureforanonlinegame,sincethisisverygame-specificandwellbeyondthescopeofwhatcanbecoveredhere.Therearemanygoodbooksandarticlesonthesubjectalreadyavailable.这篇文章不是论述怎样去设计一个好的游戏的客户端/服务器的架构,因为它本身就非常适合游戏的开发,这里讲述了它的优越性。关于这个(客户端/服务器的架构)问题,有很多好的书籍和文档都已经阐述到了。ProjectDarkstar客户端开发指南TranslateBy:ChinaEstone------------------------------------------------------------------------------------------------------------------------------------------Whatwecallhumannatureisactuallyhumanhabbit.Lesson1:HelloUserClient第一课:HelloUserClientThislessonshowshowtoconnecttothePDSandthencommunicatewithitinthebasicclient/servermode.ItisdesignedtogoalongwithLesson5oftheProjectDarkstarServerApplicationTutorialandtheHelloUserandHelloEchoexamplesinthoselessons.ItcanalsobeusedasaclientfortheSwordWorldsampleapplicationinAppendixAoftheProjectDarkstarServerApplicationTutorial.本课讲述了如何去和PDS服务器连接,之后使用这个基本的模型来与服务器进行通信。编写本节,是用于配合学习第五课、ProjectDarkstar服务器开发指南、HelloUser、HelloEcho的例子。Totestthisclient,youwillneedtostarteitherHelloUserorHelloEchoontheserver(HelloEchohasmorefunctionality).Seetheapplicationtutorialfordetailsonhowtodothis.为了测试这个客户端,你既要在服务器上启动HelloUser,也要启动HelloEcho(HelloEcho的方法比较多)。相关的操作信息请参看应用程序指南。SimpleClient简单的一个客户端----SimpleClientTheclasscom.sun.sgs.client.simple.SimpleClientisyourgatewaytothePDS.YoucreateaninstanceofSimpleClientandthenuseitanditsassociatedlistenerinterfaceSimpleClientListenertocommunicatewiththeserver.com.sun.sgs.client.simple.SimpleClient这个类是你进行PDS环境开发的一个入门的例子。你创建一个SimpleClient的实例,之后使用它以及与其相关的监听接口SimpleClientListener与服务器进行通信。Connecting连接ThefirstthingaPDSClientneedstodoisconnecttoitsserverapplication.Connectingisdoneinfoursteps:PDS客户端第一件要做的事情就是与服务器应用进行通信。连接的步骤共有四步:CreateaninstanceofSimpleClient.创建一个SimpleClient的实例ThefirstthingyouneedtodoiscreateaninstanceoftheSimpleClientclass.SimpleClient'sconstructortakesoneparameter:aSimpleClientListenertocallforcommunicationevents.Inmostbasicclients,thisislikelytheclient'smainclass,inwhichcasethecodewouldlooksomethinglikethis:你需要做的第一件事情就是创建一个SimpleClient类的实例。SimpleClient的构造器需要一ProjectDarkstar客户端开发指南TranslateBy:ChinaEstone------------------------------------------------------------------------------------------------------------------------------------------Whatwecallhumannatureisactuallyhumanhabbit.个参数:一个SimpleClientListener,用于调用通信的事件。在一般基础的客户端程序中,这就相当于一个主类,它的代码的大体看起来如下所示:publicclassMyClientimplementsSimpleClientListener{//...simpleClient=newSimpleClient(this);2.Createtheloginproperties.创建一个登陆的属性。TheloginmethodofSimpleClientexpectsoneparameteraswell,aPropertiesobject.TheSimpleClientimplementationcodeexpectstwopropertiestobeset:hostandport.Belowisanexampleofhowtosetthese:SimpleClient登陆的方法需要一个参数即可,一个Properties(属性)对象。这个SimpleClient的实现设置了两个属性:主机和端口。下面的例子演示了如何设置这些属性:PropertiesconnectProps=newProperties();connectProps.put(host,localhost);connectProps.put(port,1139);3.Calltheloginmethod.调用登陆方法Toactuallystarttheloginprocess,youcalltheloginmethod.Itispossibleforlogint
本文标题:客户端开发指南
链接地址:https://www.777doc.com/doc-1532899 .html