Click here to Skip to main content
15,910,981 members
Home / Discussions / C#
   

C#

 
QuestionHow to use WeakEventManager with reflection Pin
Kenneth Haugland23-Jan-16 23:21
mvaKenneth Haugland23-Jan-16 23:21 
SuggestionRe: How to use WeakEventManager with reflection Pin
Kornfeld Eliyahu Peter24-Jan-16 1:18
professionalKornfeld Eliyahu Peter24-Jan-16 1:18 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 1:34
professionalSascha Lefèvre24-Jan-16 1:34 
GeneralRe: How to use WeakEventManager with reflection Pin
Kornfeld Eliyahu Peter24-Jan-16 1:38
professionalKornfeld Eliyahu Peter24-Jan-16 1:38 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 1:42
professionalSascha Lefèvre24-Jan-16 1:42 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 3:25
mvaKenneth Haugland24-Jan-16 3:25 
GeneralRe: How to use WeakEventManager with reflection Pin
Kornfeld Eliyahu Peter24-Jan-16 3:42
professionalKornfeld Eliyahu Peter24-Jan-16 3:42 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 3:47
mvaKenneth Haugland24-Jan-16 3:47 
AnswerRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 2:37
professionalSascha Lefèvre24-Jan-16 2:37 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 3:11
mvaKenneth Haugland24-Jan-16 3:11 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 4:33
professionalSascha Lefèvre24-Jan-16 4:33 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 4:45
mvaKenneth Haugland24-Jan-16 4:45 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre24-Jan-16 6:14
professionalSascha Lefèvre24-Jan-16 6:14 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 17:34
mvaKenneth Haugland24-Jan-16 17:34 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 22:45
mvaKenneth Haugland24-Jan-16 22:45 
AnswerRe: How to use WeakEventManager with reflection Pin
Pete O'Hanlon24-Jan-16 7:03
mvePete O'Hanlon24-Jan-16 7:03 
GeneralRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland24-Jan-16 17:38
mvaKenneth Haugland24-Jan-16 17:38 
GeneralRe: How to use WeakEventManager with reflection Pin
Pete O'Hanlon24-Jan-16 21:25
mvePete O'Hanlon24-Jan-16 21:25 
AnswerRe: How to use WeakEventManager with reflection Pin
Kenneth Haugland25-Jan-16 7:42
mvaKenneth Haugland25-Jan-16 7:42 
GeneralRe: How to use WeakEventManager with reflection Pin
Sascha Lefèvre25-Jan-16 10:28
professionalSascha Lefèvre25-Jan-16 10:28 
QuestionHow to generate Dynamic buttons in C# from Database Values? Pin
Member 1224271723-Jan-16 19:54
Member 1224271723-Jan-16 19:54 
AnswerRe: How to generate Dynamic buttons in C# from Database Values? Pin
Mycroft Holmes23-Jan-16 20:13
professionalMycroft Holmes23-Jan-16 20:13 
GeneralRe: How to generate Dynamic buttons in C# from Database Values? Pin
Member 1224271723-Jan-16 20:25
Member 1224271723-Jan-16 20:25 
GeneralRe: How to generate Dynamic buttons in C# from Database Values? Pin
Mycroft Holmes23-Jan-16 20:30
professionalMycroft Holmes23-Jan-16 20:30 
Questionhow to implement this code for multiple clients using c sharp Pin
Member 1061979722-Jan-16 22:32
Member 1061979722-Jan-16 22:32 
the above c sharp code will send client desktop images to server . it works for single client . we want to implement this for multiple client. please provide help to implement it.

SERVER code:-
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.Remoting;
using System.Linq;
using System.Text;
using System.Net .Sockets ;
using System.Windows.Forms;
using System.Threading ;
using System.Runtime.Serialization.Formatters.Binary;
using System.Net;


namespace simpleserver
{
    public partial class Form2 : Form
    {
        private readonly    int port;
        private TcpClient client;
        private TcpListener server;
        //static public int MAX_CONN = 5;
        private NetworkStream mainstream;
        //private string ipList;
        //TcpListener myList = null;


//static int thrd = -1;

        private readonly Thread Listening;
        private readonly Thread Getimg;
        public Form2(int Port)
        {
            port = Port;
            client = new TcpClient();
            Listening = new Thread(StartListening);
            Getimg = new Thread(ReceiveImage);
            InitializeComponent();
        }


        private void StartListening()
        {
            while (!client.Connected)
            {
                //ipList = new string[MAX_CONN];
                //myList = new TcpListener(hostIP, hostPort);
                //myList.Start();

               server.Start();
               client = server.AcceptTcpClient();

               
            }
            Getimg.Start();
            
        }
        private void stop()
        {
            server.Stop();
            client = null;
            if (Listening .IsAlive )Listening .Abort ();
            if ( Getimg .IsAlive )Getimg .Abort ();
        }
        private void ReceiveImage()
        {
            BinaryFormatter binformatter = new BinaryFormatter();
            while (client.Connected)
            {
                mainstream = client.GetStream();
                pictureBox1.Image =(Image ) binformatter.Deserialize(mainstream);
              //  pictureBox2 .Image =(Image )binformatter .Deserialize (mainstream );

            }
 
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            server = new TcpListener(IPAddress .Any ,port  );
            Listening .Start ();
        }

      
    }
}


CLIENT CODE:-
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;

namespace sampleclient
{
    public partial class Form1 : Form
    {
        private readonly TcpClient client = new TcpClient();
        private NetworkStream mainStream;
        private int portNumber;

        private static Image GetDesktop()
        {
            Rectangle bounds = Screen.PrimaryScreen.Bounds;
            Bitmap screenshot = new Bitmap(bounds .Width ,bounds .Height,PixelFormat .Format32bppArgb );
            Graphics g = Graphics.FromImage(screenshot);
            g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
            return screenshot;
        }
        private void SendDesktop()
        {
            
            BinaryFormatter  binformatter = new BinaryFormatter ();
            mainStream = client.GetStream();
            binformatter.Serialize (mainStream, GetDesktop());

 
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            portNumber = int.Parse(textBox2.Text);
            try
            {
                client.Connect(textBox1.Text, portNumber);
                MessageBox.Show("connected success");
                timer1.Start();
            }
            catch (Exception)
            {
                MessageBox.Show("fail");
            }
        }

        //private void button2_Click(object sender, EventArgs e)
        //{
        //    if (button2.Text.StartsWith("share")) 
        //    {
        //        timer1.Start();
        //        button2.Text = ("stop sha");
        //    }
        //    else 
        //    {
        //        timer1 .Stop ();
        //        button2 .Text ="share sceen";
        //    }
        //}

        private void timer1_Tick(object sender, EventArgs e)
        {
            SendDesktop ();
        }
    }

}


modified 23-Jan-16 12:12pm.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.