Scut游戏服务器免费开源框架--快速开发(1)

Scut快速开发(1)

 

1        开发环境

需要安装的软件

a)        VS2010开发工具(.Net Framework 4.0以上)

 

2        HelloWorld

2.1     创建项目

打开VS2010 在菜单上选择 文件 -> 新建 -> 项目;弹出“新建项目”对话窗口,在左则展开“Visual C#”,选择“控制台应用程序”,选择“.Net Framework 4.0”后,输出项目名称(HelloWorld)及位置,再点击“确定”;如图:

 

接着在HelloWorld项目,右击点“属性”,在应用程序项设置目标框架为“.Net Framework 4

 

2.2     组件引用

项目

引用路径

HostServer

Lib\protobuf-net.dll

Lib\ ServiceStack.Common.dll

Lib\ZyGames.Framework.Common.dll

Lib\ZyGames.Framework.dll Lib\ZyGames.Framework.Plugin.dll

Lib\ZyGames.Framework.RPC.dll

//中间层

Lib\ZyGames.Framework.Game.Lang.dll

Lib\ZyGames.Framework.Game.dll

Lib\ ZyGames.Framework.Game.Contract.dll

2.3     运行程序

打开Program文件,并将Program类继承至GameSocketHost基类,实现父类方法;接着在Main方法中增加启动代码,如图:

class Program : GameSocketHost
{
    static void Main(string[] args)
    {
        new Program().Start();
    }
        
    protected override void OnConnectCompleted(object sender, ConnectionEventArgs e)
    {
        Console.WriteLine("Client:{0} connect to server.", e.Socket.RemoteEndPoint);
    }

    protected override void OnRequested(HttpGet httpGet, IGameResponse response)
    {
        Console.WriteLine("Request data:{0}", httpGet.ParamString);
    }

    protected override void OnStartAffer()
    {
        try
        {
            //时º¡À间?间?隔?更¨¹新?库a
            int cacheInterval = 600;
            GameEnvironment.Start(cacheInterval, () => true);
            Console.WriteLine("The server is staring...");
            Console.WriteLine("Helo world.");
        }
        catch (Exception ex)
        {
            Console.WriteLine("error:{0}", ex.Message);
        }
    }

    protected override void OnServiceStop()
    {
        GameEnvironment.Stop();
        Console.WriteLine("The server is stoped");
    }
}

 

F5运行程序,结果如下:

 开源地址:

GitHub地址:https://github.com/ScutGame

 

观看视频:http://v.youku.com/v_show/id_XNTk1NzI0NDE2.html

 

posted @ 2013-08-12 16:07  Scut  阅读(5129)  评论(0编辑  收藏  举报