Ejemplo n.º 1
0
 public void Send(TcpServerEventArgs arg)
 {
     arg.Client          = this;
     arg.Stream.Position = 0;
     if (arg.Stream.Length > 0)
     {
         sendEvent.Reset();
         var read = arg.Stream.Read(arg.Buffer, 0, TcpServerEventArgs.BufferSize);
         Socket.BeginSend(arg.Buffer, 0, read, SocketFlags.None, SendCallback, arg);
         sendEvent.WaitOne();
     }
 }
Ejemplo n.º 2
0
        public TcpServerEventArgs Clone(bool stream = true)
        {
            var clone = new TcpServerEventArgs {
                Client = this.Client
            };

            if (stream)
            {
                clone.Stream = new MemoryStream();
            }
            return(clone);
        }
Ejemplo n.º 3
0
        protected internal void OnDataLoad(TcpServerEventArgs arg)
        {
            NetStat.Set("Server Receive", 1, arg.Length);

            if (logEvents)
            {
                Helper.Logs.Add(new StateInfo("NetService", "DataLoad", string.Format("{0} {1} {2}",
                                                                                      arg.Client.Socket.LocalEndPoint,
                                                                                      arg.Client.Socket.RemoteEndPoint,
                                                                                      Helper.TextDisplayFormat(arg.Length, "size"))));
            }

            DataLoad?.Invoke(this, arg);

            arg.Stream.Dispose();
        }
Ejemplo n.º 4
0
 internal void Load()
 {
     ThreadPool.QueueUserWorkItem(p =>
     {
         while (Socket.Connected)
         {
             var arg = new TcpServerEventArgs
             {
                 Client = this,
                 Stream = new MemoryStream()
             };
             loadEvent.Reset();
             Socket.BeginReceive(arg.Buffer, 0, TcpServerEventArgs.BufferSize, SocketFlags.None, LoadCallback, arg);
             loadEvent.WaitOne();
         }
     });
 }