Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Afternoon, I was doing a server client TCP Network Stream project. This project can view the client's desktop to the server. I wanted to make another client that will view from the Server

What I have tried:

public partial class viewclient : Form
    {
        private readonly int port;
        private TcpClient client;

        //2nd Client
        private TcpClient client2;



        private TcpListener server;
       
        private NetworkStream mainStream;
        private NetworkStream mainStream2;

        private readonly Thread Listening;
        private readonly Thread GetImage;

        

        public viewclient(int Port)
        {
            port = Port;
           
            client = new TcpClient();
            client2 = new TcpClient();

            Listening = new Thread(StartListening);
            GetImage = new Thread(ReceiveImage);

            InitializeComponent();
        }

        private void StartListening()
        {
            while (!client.Connected)
            {

                server.Start();
                client = server.AcceptTcpClient();
                client2 = server.AcceptTcpClient();
            }
            GetImage.Start();
        }


        private void StopListening()
        {
            server.Stop();
            client = null;
            client2 = null;
            if (Listening.IsAlive) Listening.Abort();
            if (GetImage.IsAlive) GetImage.Abort();
        }

        private void ReceiveImage()
        {
            BinaryFormatter binFormatter = new BinaryFormatter();
            while (client.Connected)
            {

                mainStream = client.GetStream();
                mainStream2 = client2.GetStream();
                pictureBox1.Image = (Image)binFormatter.Deserialize(mainStream);
                pictureBox2.Image = (Image)binFormatter.Deserialize(mainStream2);

            }
        }


        private void ReceiveImage1()
        {


            BinaryFormatter binFormatter = new BinaryFormatter();
            while (client2.Connected)
            {
                mainStream = client2.GetStream();
                pictureBox2.Image = (Image)binFormatter.Deserialize(mainStream);
            }

        }




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

        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            StopListening();
        }
Posted
Updated 9-Apr-18 2:16am

Maybe this will suit your needs: Windows Remote Desktop Application[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900