예제 #1
0
 private void NewSession(TcpClientSession session)
 {
     session.SentCompleted += (s, e) =>
     {
         IncreaseSentSize(e.Header.DataLength + Header.HEADER_SIZE);
         if (e.Header.Key == MessageKeys.Literal)
         {
             var msg = (BytesMessage)e;
             Print($"{e.Header.From}:{MessageHelper.LiteralEncoding.GetString(msg.Bytes)}");
         }
         else if (e.Header.Key == MessageKeys.File)
         {
             Print($"{e.Header.From}:{e.Header.State}");
         }
     };
     session.Received += (s, e) =>
     {
         if (e.Header.Key == MessageKeys.Literal)
         {
             var msg = (BytesMessage)e;
             Print($"{e.Header.From ?? "system"}:{MessageHelper.LiteralEncoding.GetString(msg.Bytes)}");
         }
         else if (e.Header.Key == MessageKeys.Remote)
         {
             Remote(session, e.Header.From);
         }
         else if (e.Header.Key == MessageKeys.RemoteStop)
         {
         }
         else if (e.Header.Key == MessageKeys.RemoteImage)
         {
             var bytesMesaage = e as BytesMessage;
             var terminal     = RemoteForm.Get(e.Header.From);
             if (terminal == null)
             {
                 session.Send(MessageHelper.CreateRemoteStopMessage(this.userName, e.Header.From, null));
                 return;
             }
             if (terminal.Disposing || terminal.IsDisposed)
             {
                 return;
             }
             if (!terminal.Visible)
             {
                 this.Invoke(new MethodInvoker(() =>
                 {
                     terminal.Show();
                 }));
             }
             terminal.Draw(bytesMesaage.Bytes);
             Task.Run(() =>
             {
                 Thread.Sleep(1000);
                 SendRemoteImageRequest(e.Header.From);
             });
         }
     };
 }
예제 #2
0
 private void OtherProxyConnectedHandle(ProxySession session, TcpClientSession targetSession)
 {
     if (targetSession != null)
     {
         byte[] data = Encoding.ASCII.GetBytes(m_SendingHeader);
         m_SendingHeader = null;
         targetSession.Send(data, 0, data.Length);
     }
 }
예제 #3
0
        // Token: 0x060005C5 RID: 1477 RVA: 0x000198CC File Offset: 0x00017ACC
        private void SendDataFragment(WebSocket websocket, int opCode, byte[] playloadData, int offset, int length)
        {
            byte[]           array  = this.EncodeDataFrame(opCode, playloadData, offset, length);
            TcpClientSession client = websocket.Client;

            if (client != null)
            {
                client.Send(array, 0, array.Length);
            }
        }
        internal void RequestDataReceived(byte[] buffer, int offset, int length)
        {
            if (m_TargetSession == null)
            {
                Logger.Error("Cannot receive data before when target socket is connected");
                this.Close();
                return;
            }

            m_TargetSession.Send(buffer, offset, length);
        }
예제 #5
0
    //---------------------------------------------------------------------
    public void Send(ushort method_id, byte[] data)
    {
        ushort data_len = 0;

        byte[] send_buf = null;
        if (data == null)
        {
            data_len = sizeof(ushort);
            send_buf = new byte[sizeof(ushort) + data_len];
        }
        else
        {
            data_len = (ushort)(sizeof(ushort) + data.Length);
            send_buf = new byte[sizeof(ushort) + data_len];
        }
        Array.Copy(BitConverter.GetBytes(data_len), 0, send_buf, 0, sizeof(ushort));
        Array.Copy(BitConverter.GetBytes(method_id), 0, send_buf, sizeof(ushort), sizeof(ushort));
        if (data != null && data.Length > 0)
        {
            Array.Copy(data, 0, send_buf, sizeof(ushort) * 2, data.Length);
        }
        mSession.Send(send_buf);
    }
예제 #6
0
 private void TcpClientAccepted(TcpClientSession session)
 {
     session.Received += (s, e) =>
     {
         if (e.Header.Key == MessageKeys.Login)
         {
             var userName = e.Header.From;
             session.Send(MessageHelper.CreateLiteralMessage($"Hello,{userName}", null, userName, "system greeting"));
             users.Add(new User()
             {
                 Session = session, UserName = userName
             });
             Print($"{userName} is logged in.");
         }
         else if (e.Header.To != null)
         {
             var user = users.FirstOrDefault(u => u.UserName == e.Header.To);
             if (user == null)
             {
                 session.Send(MessageHelper.CreateLiteralMessage($"user {e.Header.To} not found.", null, e.Header.From, "system reply"));
             }
             else
             {
                 user.Session.Send(e);
             }
         }
         else if (e.Header.Key == MessageKeys.Literal)
         {
             var msg = (BytesMessage)e;
             Print($"{e.Header.From}:{MessageHelper.LiteralEncoding.GetString(msg.Bytes)}");
         }
         else if (e.Header.Key == MessageKeys.CloseSession)
         {
             session.Disconnect("client disconnected");
         }
     };
 }
예제 #7
0
        // Token: 0x060005C7 RID: 1479 RVA: 0x000198FC File Offset: 0x00017AFC
        public override void SendData(WebSocket websocket, IList <ArraySegment <byte> > segments)
        {
            List <ArraySegment <byte> > list = new List <ArraySegment <byte> >(segments.Count);
            int num = segments.Count - 1;

            for (int i = 0; i < segments.Count; i++)
            {
                ArraySegment <byte> arraySegment = segments[i];
                list.Add(new ArraySegment <byte>(this.EncodeDataFrame((i == 0) ? 2 : 0, i == num, arraySegment.Array, arraySegment.Offset, arraySegment.Count)));
            }
            TcpClientSession client = websocket.Client;

            if (client != null)
            {
                client.Send(list);
            }
        }
예제 #8
0
        private void Remote(TcpClientSession session, string userName)
        {
            // 新建一个和屏幕大小相同的图片
            Bitmap catchBmp = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);
            // 创建一个画板,让我们可以在画板上画图
            // 这个画板也就是和屏幕大小一样大的图片
            // 我们可以通过Graphics这个类在这个空白图片上画图
            Graphics g = Graphics.FromImage(catchBmp);

            // 把屏幕图片拷贝到我们创建的空白图片 CatchBmp中
            g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height));

            var stream = new MemoryStream();

            catchBmp.Save(stream, ImageFormat.Png);
            var array      = stream.ToArray();
            var compressed = Helper.Compress(array);

            session.Send(MessageHelper.CreateRemoteImageMessage(compressed, this.userName, userName, null));
            g.Dispose();
            catchBmp.Dispose();
            stream.Dispose();
        }