Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
 
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::::
 
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:::
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 22-Mar-11 11:27am
Edited 25-Mar-11 7:41am
v2
Comments
Rick Shaub at 22-Mar-11 17:11pm
   
Can you please post your code on this site?
Sandeep Mewara at 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 at 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 at 24-Mar-11 14:57pm
   
ya okay
posting...
ankitpsaraogi at 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
dmageiras at 24-Mar-11 15:47pm
   
You are welcome. But it would be better if you included your code as a part of the question, not as an answer.
Concerning wireless router, I dont think it makes a difference. Can you ping your laptop from your desktop and vice versa?
ankitpsaraogi at 25-Mar-11 6:26am
   
Hmm... Actually My Laptop is out of order.. will surely check once again as soon as it gets all right... till thn wil also try in a VPN..
ankitpsaraogi at 24-Mar-11 15:06pm
   
And Ya are u able to see the screen also in the Client???
dmageiras at 24-Mar-11 15:51pm
   
No I cant see the screen. I guess it has something to do with serialization, but I am not sure. Any how, I can get the sum, which means that this part is working properly. Make sure you can see the sum also, ensuring there are no connection issues and later try to resolve the screen problem.
ankitpsaraogi at 24-Mar-11 15:34pm
   
And also how can i make it work over Internet?
dmageiras at 24-Mar-11 15:52pm
   
I got it working over Internet through VPN, but first you have to solve the LAN problem.
ankitpsaraogi at 25-Mar-11 17:11pm
   
Hi,
I have tried over VPN too
And its working
It will work over LAN too
Maybe I did nt properly configure the firewall, the first time I tried
However, I even got to see the screen once but only once
and CD Rom is gettng ejected but the Randomize Button is not working
And even it is not working over the Internet
dmageiras at 28-Mar-11 15:15pm
   
Disable firewall.
ankitpsaraogi at 26-Mar-11 13:16pm
   
Hey, I tried it
All the features are working
but I have to turn off the firewall
thats a big issue...
but still i would like to know how can i work it over internet where I cannot get the ping of the other pc
dmageiras at 28-Mar-11 15:14pm
   
Adjust your firewall to enable Ping.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 25 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100