コード例 #1
0
ファイル: TCPClientForm.cs プロジェクト: Olexyy/TcpServer
        private void ScreenSender()
        {
            Message mes = new Message(MessageTypes.mail, this.MessengerClient.User);
            TCPServerClientInteractEventArgs arg = new TCPServerClientInteractEventArgs(mes, true, true);

            this.Client.Send(arg);
            do
            {
                using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
                {
                    using (Graphics g = Graphics.FromImage(bmpScreenCapture))
                    {
                        g.CopyFromScreen(0, 0, 0, 0, bmpScreenCapture.Size);
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            Bitmap resized = new Bitmap(bmpScreenCapture, new Size(240, 160));
                            resized.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            byte[]  binaryData = memoryStream.ToArray();
                            Message message    = new Message(MessageTypes.cast, this.MessengerClient.User, "", binaryData);
                            TCPServerClientInteractEventArgs args = new TCPServerClientInteractEventArgs(message, true, true);
                            this.Client.Send(args);
                        }
                    }
                }
                Thread.Sleep(2000);
            } while (this.Visible && this.MessengerClient.IsStreamer);
        }
コード例 #2
0
ファイル: TCPClient.cs プロジェクト: Olexyy/TcpServer
        private void GetObject <T>(TCPServerClientInteractEventArgs args)
        {
            string data       = Encoding.UTF8.GetString(args.Bytes, 0, args.BytesCount);
            T      dataObject = new JavaScriptSerializer().Deserialize <T>(data);

            args.Object = dataObject;
        }
コード例 #3
0
ファイル: TCPClientForm.cs プロジェクト: Olexyy/TcpServer
        private void buttonLogout_Click(object sender, EventArgs e)
        {
            Message message = new Message(MessageTypes.logout, this.MessengerClient.User);
            TCPServerClientInteractEventArgs args = new TCPServerClientInteractEventArgs(message, true, true);

            this.Client.Send(args);
        }
コード例 #4
0
ファイル: TCPClientForm.cs プロジェクト: Olexyy/TcpServer
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            User    user    = new User(this.textBoxUserName.Text);
            Message message = new Message(MessageTypes.login, user);
            TCPServerClientInteractEventArgs args = new TCPServerClientInteractEventArgs(message, true, true);

            this.Client.Send(args);
        }
コード例 #5
0
ファイル: TCPClientForm.cs プロジェクト: Olexyy/TcpServer
 private void buttonShowDesktop_Click(object sender, EventArgs e)
 {
     if (!this.MessengerClient.IsStreamer)
     {
         new Thread(this.ScreenSender).Start();
     }
     else
     {
         Message message = new Message(MessageTypes.cast_end, this.MessengerClient.User);
         TCPServerClientInteractEventArgs args = new TCPServerClientInteractEventArgs(message, true, true);
         this.Client.Send(args);
     }
 }
コード例 #6
0
ファイル: TCPClient.cs プロジェクト: Olexyy/TcpServer
 public void Send(TCPServerClientInteractEventArgs args)
 {
     try {
         if (this.DataType != null)
         {
             this.SetObject(args);
         }
         int bytesCount = this.BaseSocket.Send(args.Bytes);
     }
     catch (Exception ex) {
         this.WatchDog(TCPServerClientMessages.SendFail);
     }
 }
コード例 #7
0
ファイル: TCPClientForm.cs プロジェクト: Olexyy/TcpServer
 private void buttonPost_Click(object sender, EventArgs e)
 {
     if (this.textBoxNewMessage.Text != String.Empty)
     {
         Message message = new Message(MessageTypes.post, this.MessengerClient.User, this.textBoxNewMessage.Text);
         TCPServerClientInteractEventArgs args = new TCPServerClientInteractEventArgs(message, true, true);
         this.Client.Send(args);
         this.Invoke(new Action(() => this.textBoxNewMessage.Text = String.Empty));
     }
     else
     {
         MessageBox.Show("Text is not set.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #8
0
ファイル: TCPClient.cs プロジェクト: Olexyy/TcpServer
        private void AsyncInteract(object param)
        {
            Socket baseSocket = param as Socket;

            try
            {
                while (true)
                {
                    byte[] bytes      = new byte[this.BufferSize];
                    int    bytesCount = baseSocket.Receive(bytes);
                    TCPServerClientInteractEventArgs args = new TCPServerClientInteractEventArgs();
                    args.Bytes      = bytes;
                    args.BytesCount = bytesCount;
                    if (this.DataType != null)
                    {
                        MethodInfo method = typeof(TCPServerClient).GetMethod("GetObject", BindingFlags.Instance | BindingFlags.NonPublic);
                        try
                        {
                            method.MakeGenericMethod(this.DataType).Invoke(this, new object[] { args });
                        }
                        catch (Exception ex)
                        {
                            this.WatchDog(TCPServerClientMessages.ParseFail);
                        }
                    }
                    if (this.ClientInteractEvent != null)
                    {
                        this.ClientInteractEvent(this, args);
                    }
                    if (args.CallBack)
                    {
                        if (this.DataType != null)
                        {
                            this.SetObject(args);
                        }
                        bytesCount = baseSocket.Send(args.Bytes);
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                this.WatchDog(TCPServerClientMessages.Disconnected);
            }
            catch (Exception ex)
            {
                this.WatchDog(TCPServerClientMessages.ReceiveFail);
            }
        }
コード例 #9
0
        public void InteractHandler(object o, TCPServerClientInteractEventArgs args)
        {
            Message message = args.Object as Message;

            switch (message.MessageType)
            {
            case MessageTypes.login_success:
                lock (this.locker)
                {
                    this.LoggedIn = true;
                    this.User     = message.User;
                }
                break;

            case MessageTypes.logout_success:
                lock (this.locker)
                {
                    this.LoggedIn = false;
                    this.User     = null;
                }
                break;

            case MessageTypes.cast_success:
                lock (this.locker)
                {
                    this.IsStreamer = true;
                }
                break;

            case MessageTypes.cast_end_success:
                lock (this.locker)
                {
                    this.IsStreamer = false;
                }
                break;

            default:
                break;
            }
        }
コード例 #10
0
ファイル: TCPClientForm.cs プロジェクト: Olexyy/TcpServer
        private void InteractHandler(object o, TCPServerClientInteractEventArgs args)
        {
            Message message = args.Object as Message;

            switch (message.MessageType)
            {
            case MessageTypes.login_success:
                this.Invoke(new Action(() => {
                    this.Message.Text = "[Messenger]: Logged in...";
                    this.ButtonsPattern(true, false, false, false, true, true, true);
                }));
                break;

            case MessageTypes.logout_success:
                this.Invoke(new Action(() => {
                    this.Message.Text = "[Messenger]: Logged out...";
                    this.ButtonsPattern(false, false, true, true, false, false, false);
                    this.textBoxFriendsOnline.Text = "0";
                }));
                break;

            case MessageTypes.post:
                this.Invoke(new Action(() => {
                    this.Message.Text = "[Messenger]: New messages received...";
                    this.MessageList.Items.Add(message.User.Name);
                    this.MessageList.Items[this.MessageList.Items.Count - 1].SubItems.Add(DateTime.Now.ToShortDateString());
                    this.MessageList.Items[this.MessageList.Items.Count - 1].SubItems.Add(message.Text);
                }));
                break;

            case MessageTypes.post_success:
                this.Invoke(new Action(() => {
                    this.Message.Text = "[Messenger]: Message posted...";
                }));
                break;

            case MessageTypes.group:
                this.Invoke(new Action(() => {
                    this.Message.Text = "[Messenger]: Changes in group...";
                    this.textBoxFriendsOnline.Text = message.Text;
                }));
                break;

            case MessageTypes.cast_success:
                this.Invoke(new Action(() => {
                    this.buttonShowDesktop.Text = "Stop streaming";
                }));
                break;

            case MessageTypes.cast_end_success:
                this.Invoke(new Action(() => {
                    this.buttonShowDesktop.Text = "Show screen";
                }));
                break;

            case MessageTypes.cast:
                Image image = Image.FromStream(new MemoryStream(message.BinaryData));
                this.Invoke(new Action(() => {
                    if (!this.desktopForm.Visible)
                    {
                        this.desktopForm.Show();
                    }
                    if (message.User.Id != this.MessengerClient.User.Id)
                    {
                        this.buttonShowDesktop.Enabled = false;
                    }
                    this.desktopForm.SetScreen(image);
                }));
                break;

            case MessageTypes.cast_end:
                this.Invoke(new Action(() => {
                    if (this.desktopForm.Visible)
                    {
                        this.desktopForm.Hide();
                    }
                    if (!this.buttonShowDesktop.Enabled)
                    {
                        this.buttonShowDesktop.Enabled = true;
                    }
                }));
                break;

            case MessageTypes.mail_success:
                this.Invoke(new Action(() => {
                    this.Message.Text = "[Messenger]: Mail sent...";
                }));
                break;

            default:
                break;
            }
        }
コード例 #11
0
ファイル: TCPClient.cs プロジェクト: Olexyy/TcpServer
        private void SetObject(TCPServerClientInteractEventArgs args)
        {
            string serialized = new JavaScriptSerializer().Serialize(args.Object);

            args.Bytes = Encoding.UTF8.GetBytes(serialized);
        }