First example, EchoService

1. 新建一个名叫 “EchoService” 的空白项目 
2. 添加SuperSocket的Common和SocketBase这两个dll或者项目引用到EchoService项目

3. 新增名为EchoServer和EchoSession的类,如下图

EchoSession.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;
 
namespace SuperSocket.QuickStart.EchoService
{
    public class EchoSession : AppSession<EchoSession>
    {
        public override void StartSession()
        {
            SendResponse("Welcome to EchoServer!");
        }
 
        public override void HandleExceptionalError(Exception e)
        {
            SendResponse("Server side error occurred!");
        }
    }
}

EchoServer.cs

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;
 
namespace SuperSocket.QuickStart.EchoService
{
    public class EchoServer : AppServer<EchoSession>
    {
 
    }
}

 

4. 添加命令类

ECHO.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase.Command;
 
namespace SuperSocket.QuickStart.EchoService.Command
{
    public class ECHO : StringCommandBase<EchoSession>
    {
        #region CommandBase<EchoSession> Members
 
        public override void ExecuteCommand(EchoSession session, StringCommandInfo commandInfo)
        {
            session.SendResponse(commandInfo.Data);
        }
 
        #endregion
    }
}

注意: 命令类必须为public.

5. 编译项目 “EchoService” 然后拷贝项目输出到"SocketService"这个项目的输出目录 (请先提前编译SocketService项目)

6. 更新SocketService的配置文件app.config 来启用“EchoService”

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="socketServer" type="SuperSocket.SocketEngine.Configuration.SocketServiceConfig, SuperSocket.SocketEngine"/>
    </configSections>
    <appSettings>
        <add key="ServiceName" value="EchoService"/>
    </appSettings>
    <socketServer loggingMode="IndependantFile">
        <servers>
            <server name="EchoServer"
                 serviceName="EchoService" ip="Any" port="911" mode="Async">
            </server>
        </servers>
        <services>
            <service name="EchoService"
                     type="SuperSocket.QuickStart.EchoService.EchoServer, SuperSocket.QuickStart.EchoService" />
        </services>
    </socketServer>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
    </startup>
</configuration>

请注意配置文件中的 "socketServer" 节点.

7. 运行“RunServer.bat” 然后输入任意键启动SuperSocket, 然后你就可以通过telnet client来测试你的EchoService了 (你也可以运行"InstallService.bat"来将SuperSocket安装成服务,  服务的名称是在app.config的appSetting以"ServiceName"为key的值,你可以按照项目需要修改它),测试方式如下,输入“ECHO Any message”:

本文源代码在SuperSocket的源代码中QuickStart目录中已包含:

http://supersocket.codeplex.com/releases/

supersocket--SuperSocket 1.4系列文档(1) 第一个例子, EchoService的更多相关文章

  1. AIO系列文档(2)----TIO使用

    AIO系列文档(1)----图解ByteBuffer中介绍了ByteBuffer用法,下面通过介绍t-io介绍如何使用: hello world例子简介 本例子演示的是一个典型的TCP长连接应用,代码 ...

  2. 老猿学5G扫盲贴:3GPP规范文档命名规则及同系列文档阅读指南

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 在学习5G规范过程中,有些内容把握不定的时候,有时 ...

  3. Sharepoint学习笔记—ECM系列—文档列表的Metedata Navigation与Key Filter功能的实现

    如果一个文档列表中存放了成百上千的文档,想要快速的找到你想要的还真不是件容易的事,Sharepoint提供了Metedata Navigation与Key Filter功能可以帮助我们快速的过滤和定位 ...

  4. Sharepoint学习笔记—ECM系列--文档集(Document Set)的实现

    文档集是 SharePoint Server 2010 中的一项新功能,它使组织能够管理单个可交付文档或工作产品(可包含多个文档或文件).文档集是特殊类型的文件夹,它合并了唯一的文档集属性以及文件夹和 ...

  5. Thinking in Java系列 文档+代码+简评

    声明:本人无意侵犯原作者的版权,这里可下载的文档都属于作者自行开放下载的,统一放置在这里是因为不可预测的原因使得原文档和代码不方便下载,故将我所收集的内容统一在这里,如果这里的内容侵犯了别人,请告知我 ...

  6. 微软官方的.net系列文档

    闲下来的时候给自己补充补充基础,微软官方的相关技术文档地址,最新最全最官方:https://docs.microsoft.com/zh-cn/ 其中.NET专区:https://docs.micros ...

  7. Unity文档阅读 第一章 入门

    Before you learn about dependency injection and Unity, you need to understand why you should use the ...

  8. 一起买Beta版本系列文档

    一起买beta版本文档报告汇总 031402401鲍亮 031402402曹鑫杰 031402403常松 031402412林淋 031402418汪培侨 031402426许秋鑫 一.Beta版本冲 ...

  9. JEECMS8——系列文档

    jeecms8 系列文章地址 https://blog.csdn.net/weixin_37490221/article/details/78652035

随机推荐

  1. virtualbox 复制多个虚拟机 (宿主机redhat)

    我用VirtualBox做了一个winxp虚拟镜像. 想实现不重新安装而直接复制几个,也就是同时装载几个虚拟机. 但是直接复制已安装好机子的vdi文件,系统会报uuid已存在的错误. 所以,就需要修改 ...

  2. 1 & 167. Two Sum I & II ( Input array is sorted )

    Input array is sorted: Use binary search or two pointers Unsorted: Use hash map, key = target - a[i] ...

  3. UML的基本关联

     First, a dependency is a semantic relationship between two model elements in which a change to on ...

  4. Invalid file permission Please regenerate them with cacaoadm create-keys --force

    1.服务器重启之后,启动cacao报错,提示无效的文件权限. [root@ldapserver bin]# ./cacaoadm start Invalid file permission: [/ho ...

  5. 【并查集+拓扑排序】【HDU1811】【Rank of Tetris】

    题意:给你3种关系 A=B,A>B,A<B 问是否排名方式唯一,或者存在矛盾 解 1.读入数据先处理 =号 用并查集的祖先作为代表元素,其他儿子节点都等于跟这个点重叠. 再读入 '< ...

  6. memcached 内存管理 分析(转)

    Memcached是一个高效的分布式内存cache,了解memcached的内存管理机制,便于我们理解memcached,让我们可以针对我们数据特点进行调优,让其更好的为我所用.这里简单谈一下我对me ...

  7. idea git merge代码

    1.点击idea 右下角的红框区域 2.出现如下截图,第一个红框是本地dev merge,也就是说可以从从本地的dev仓库merge,第二个红框表明可以从远程的git dev merge 第三个红框表 ...

  8. Zepto.js touch模块深入分析 解决手机点击事件

    源码: // Zepto.js // (c) 2010-2015 Thomas Fuchs // Zepto.js may be freely distributed under the MIT li ...

  9. T-sql编程

    T-Sql中的变量都是@符号开头的 以一个@符号开头,叫做“用户声明的变量” 以两个@@开头的叫做"全局变量","系统变量",是由系统来维护的.无需我们维护 - ...

  10. 总结PHP中几种常用的网页跳转代码

    网页跳转的意思就是指当你在浏览器中访问A页面时,会自动跳转到B页面,往往网页跳转用在404页面中会比较多点.至于怎么实现网页跳转,网上已经提供了很多的方法,有些方法是不可行的,经过测试,叶德华今天就在 ...