zoukankan      html  css  js  c++  java
  • 建立网络服务器

    SupperSocket官网:http://www.supersocket.net/

    SupperSocket 源码和库的下载地址:https://supersocket.codeplex.com/releases/view/161987

    准备:下载SupperSocket的Lib库文件:

    新建C#工程,修改目标框架如下图:

    在项目中添加引用(.net4.0版本):

    在创建服务器前,我们需要创建3个必要的文件,Server、Session、Command这三个文件:

    Server负责管理客户端和服务器之间的连接Session,Command负责命令处理;

    1. 创建AppServer

    新建AppServer文件:

    在该类中重写服务器核心代码:

    2. 创建AppSession

    新建AppSession文件:

    3. 创建Command文件:

    新建AppCommand文件:

     

    4. Main函数处理

    namespace NetworkServer_ElectricalPowerSystem
    {
        class Program
        {
            static void Main(string[] args)
            {
                ElectricServer_jqm EServer = new ElectricServer_jqm();
    
                //设置坚挺端口号
                if (!EServer.Setup(2012)) //Setup with listening port
                {
                    Console.WriteLine("Failed to setup!");
                    Console.ReadKey();
                    return;
                }
    
                //启动服务器
                if (!EServer.Start())
                {
                    Console.WriteLine("Failed to start!");
                    Console.ReadKey();
                    return;
                }
    
                Console.WriteLine("The server started successfully, press key 'q' to stop it!");
    
                while (Console.ReadKey().KeyChar != 'q')
                {
                    Console.WriteLine();
                    continue;
                }
    
                //Stop the appServer
                EServer.Stop();
    
                Console.WriteLine("The server was stopped!");
                Console.ReadKey();
            }
        }
    }
    View Code

    5. 使用window7 自带的远程连接(telnet)测试:

    
    

     ==================================

    简单的构建好的Server项目:

    https://files.cnblogs.com/files/jqm304775992/ElectricalPowerSystemNetworkServer_JQM.rar

  • 相关阅读:
    MySQL数据模型
    Spring循环依赖
    @Autowired和@Resource区别
    Kafka概念
    阻塞队列
    线程池原理
    Spring AOP
    JVM 史上最最最完整深入解析(12000 字噢)
    Dubbo配置信息
    友情链接
  • 原文地址:https://www.cnblogs.com/jqm304775992/p/4870750.html
Copyright © 2011-2022 走看看