Example #1
0
 public JsonLinePacketServer(IJsonSerializationServerAdapter SerializationServerAdapter, CheckCommandAllowedDelegate CheckCommandAllowed, IBinaryTransformer Transformer = null, int ReadBufferSize = 8 * 1024)
 {
     this.ss = SerializationServerAdapter;
     this.c  = new Context(ReadBufferSize);
     this.CheckCommandAllowed = CheckCommandAllowed;
     this.Transformer         = Transformer;
     this.ss.ServerEvent     += (CommandName, CommandHash, Parameters) =>
     {
         var Bytes = TextEncoding.UTF8.GetBytes(String.Format(@"/svr {0} {1}" + "\r\n", CommandName + "@" + CommandHash.ToString("X8", System.Globalization.CultureInfo.InvariantCulture), Parameters));
         lock (c.WriteBufferLockee)
         {
             if (Transformer != null)
             {
                 Transformer.Transform(Bytes, 0, Bytes.Length);
             }
             c.WriteBuffer.Add(Bytes);
         }
         if (OutputByteLengthReport != null)
         {
             OutputByteLengthReport(CommandName, Bytes.Length);
         }
         if (this.ServerEvent != null)
         {
             this.ServerEvent();
         }
     };
 }
 public JsonHttpPacketServer(IJsonSerializationServerAdapter SerializationServerAdapter, CheckCommandAllowedDelegate CheckCommandAllowed)
 {
     this.ss = SerializationServerAdapter;
     this.c  = new Context();
     this.CheckCommandAllowed = CheckCommandAllowed;
     this.ss.ServerEvent     += (CommandName, CommandHash, Parameters) =>
     {
         var rjo = new JObject();
         rjo["commandName"] = new JValue(CommandName);
         rjo["commandHash"] = new JValue(CommandHash.ToString("X8", System.Globalization.CultureInfo.InvariantCulture));
         rjo["parameters"]  = new JValue(Parameters);
         lock (c.WriteBufferLockee)
         {
             c.WriteBuffer.Add(rjo);
         }
         if (this.ServerEvent != null)
         {
             this.ServerEvent();
         }
     };
 }