Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please check my Program and help me.
Its running succesfully in the local machine but not working over LAN or Internet

http://www.4shared.com/file/mYSD5KDg/RemoteApp.html[^]



CODE:

Remote Class:::

xx.cs file:

C++
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.Remoting;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;
using System.Runtime.InteropServices;
namespace remoteclass
{


    public class xx : MarshalByRefObject
    {

        public int sum(int a, int b)
        {

            return a + b;

        }

        private static Bitmap bmpScreenshot;
        int k = 0;
        private static Graphics gfxScreenshot;

        public MemoryStream screenshot()
        {
            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap

            gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            // Take the screenshot from the upper left corner to the right bottom corner

            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            // Save the screenshot to the specified path that the user has chosen

            //pictureBox1.Image = bmpScreenshot;
               // bmpScreenshot.Save("e:\\screen.png", ImageFormat.Png);

            MemoryStream ms = new MemoryStream();
            SoapFormatter formatter = new SoapFormatter();
            formatter.Serialize(ms, bmpScreenshot);
            ms.Position = 0;



            return ms;






        }
        [DllImport("winmm.dll", EntryPoint = "mciSendStringA")]
        public static extern void mciSendStringA(string lpstrCommand,
               string lpstrReturnString, long uReturnLength, long hwndCallback);
        string rt = "";
        public void EjectCdTray()
        {
            mciSendStringA("set CDAudio door open", rt, 127, 0);
        }
        public void CloseCdTray()
        {
            mciSendStringA("set CDAudio door closed", rt, 127, 0);
        }
        public void CursorSet(int X, int Y)
        {
            Cursor.Position = new Point(X,Y);
        }

    }


}



Remote Client::::

MSIL
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Serialization.Formatters.Soap;
using System.Threading;



namespace remoteclient
{

    public partial class Form1 : Form
    {

        //TcpChannel ch = new TcpChannel();

        remoteclass.xx obj = new remoteclass.xx();

        public Form1()
        {

            InitializeComponent();

        }





        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                //ChannelServices.RegisterChannel(ch);

                obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),

                               "tcp://"+txtPath.Text+":8085/Ankit");

                int x = Int32.Parse(textBox1.Text);

                int y = Int32.Parse(textBox2.Text);

                textBox3.Text = (obj.sum(x, y)).ToString();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Width = this.Width-36;
            pictureBox1.Height = this.Height - 48-36;

        }



        remoteclass.xx abc = new remoteclass.xx();
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                ////abc.screenshot(pictureBox1);
                //obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
                //    "tcp://" + txtPath.Text + ":8085/Ankit");
                //SoapFormatter formatter = new SoapFormatter();
                ////System.IO.MemoryStream ms = new System.IO.MemoryStream();
                ////ms = obj.screenshot();

                ////ms.Position = 0;
                ////obj.screenshot().Position = 0;
                //pictureBox1.Image = (Bitmap)formatter.Deserialize(obj.screenshot());
                //obj.screenshot().Close();

                if(!backgroundWorker1.IsBusy)
                backgroundWorker1.RunWorkerAsync();


            }
            catch (Exception ex)
            {
                timer1.Enabled = false;

                MessageBox.Show(ex.ToString());

            }

        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            pictureBox1.Width = this.Width-36;
            pictureBox1.Height = this.Height - 48-36;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                //abc.screenshot(pictureBox1);
                obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
                    "tcp://" + txtPath.Text + ":8085/Ankit");
                SoapFormatter formatter = new SoapFormatter();
                //System.IO.MemoryStream ms = new System.IO.MemoryStream();
                //ms = obj.screenshot();

                //ms.Position = 0;
                //obj.screenshot().Position = 0;
                e.Result = (Bitmap)formatter.Deserialize(obj.screenshot());
                //obj.screenshot().Close();

            }
            catch (Exception ex)
            {
                timer1.Enabled = false;

                MessageBox.Show(ex.ToString());

            }
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            pictureBox1.Image = (Bitmap)e.Result;


        }

        private void btnEject_Click(object sender, EventArgs e)
        {
            try
            {
                obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),

                                   "tcp://" + txtPath.Text + ":8085/Ankit");
                obj.EjectCdTray();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            try
            {
                obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),

                                   "tcp://" + txtPath.Text + ":8085/Ankit");
                obj.CloseCdTray();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {

                if (timer1.Enabled)
                {
                    obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
                                       "tcp://" + txtPath.Text + ":8085/Ankit");
                    int X = e.X * pictureBox1.Image.Size.Width / pictureBox1.Size.Width;
                    int Y = e.Y * pictureBox1.Image.Size.Height / pictureBox1.Size.Height;
                    obj.CursorSet(X, Y);
                }
            }
            catch
            {

            }
        }
        int rndMouse;
        private void btnRndm_Click(object sender, EventArgs e)
        {
            try
            {
                rndMouse = 0;
                obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
                                           "tcp://" + txtPath.Text + ":8085/Ankit");
                Random random = new Random();
                while (rndMouse == 0)
                    obj.CursorSet(random.Next(pictureBox1.Image.Width), random.Next(pictureBox1.Image.Height));
            }
            catch
            {
            }

        }

        private void btnMouseStop_Click(object sender, EventArgs e)
        {
            rndMouse = 1;
        }


    }

}



RemoteServer:::
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using Microsoft.Win32;


namespace remoteserver
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            TcpChannel ch = new TcpChannel(8085);

            ChannelServices.RegisterChannel(ch);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof

                           (remoteclass.xx), "Ankit", WellKnownObjectMode.Singleton);
            //RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            //if(rkApp.GetValue("RemoteServer")==null)
            //rkApp.SetValue("RemoteServer", Application.ExecutablePath.ToString());

        }
    }
}
Posted
Updated 25-Mar-11 6:41am
v2
Comments
Rick Shaub 22-Mar-11 17:11pm    
Can you please post your code on this site?
Sandeep Mewara 22-Mar-11 17:19pm    
Better would be, you share what you program does and then the issue/error you get with the lines around the issue.

This will get you quick response. Hardly one would download, run and then suggest a resolution.
dmageiras 22-Mar-11 18:09pm    
Your code seems right to me: I can get the sum over VPN. Have you checked your firewall?
Btw, if you want real help, you'd better follow Rick's and Sandeep's advice.
ankitpsaraogi 24-Mar-11 14:57pm    
ya okay
posting...
ankitpsaraogi 24-Mar-11 15:02pm    
I have posted my code...
And dmageiras Hmm...
Ya i have checked...
actually I have tried between my Laptop(WINdows XP) and My DesktopPC(WINdows 7) connected by a wireless router...
DOes this make any differencE???
and thank you for trying my code

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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