4 Replies - 1872 Views - Last Post: 22 August 2012 - 02:31 PM Rate Topic: -----

#1 Boosi1  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-July 12

possible to control other computer? c#

Posted 22 August 2012 - 10:19 AM

hi i wanted to ask you if i can like control other computer (like shutdown computer) through sockets lets say with this code:
server:
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
public class serv
{
public static void Main()
{
try
{
IPAddress ipAd = IPAddress.Parse("172.21.5.99"); //use local m/c IP address, and use the same in the client
/* Initializes the Listener */
TcpListener myList=new TcpListener(ipAd,8001);
/* Start Listeneting at the specified port */
myList.Start();
Console.WriteLine("The server is running at port 8001...");
Console.WriteLine("The local End point is :" + myList.LocalEndpoint );
Console.WriteLine("Waiting for a connection.....");
Socket s=myList.AcceptSocket();
Console.WriteLine("Connection accepted from "+s.RemoteEndPoint);
byte[] b=new byte[100];
int k=s.Receive(B)/>;
Console.WriteLine("Recieved...");
for (int i=0;i<k;i++)
Console.Write(Convert.ToChar(b[i]));
ASCIIEncoding asen=new ASCIIEncoding();
s.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement");
/* clean up */
s.Close();
myList.Stop();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}


client:
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Sockets;
public class clnt
{
public static void Main()
{
try
{
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");
tcpclnt.Connect("172.21.5.99",8001); // use the ipaddress as in the server program
Console.WriteLine("Connected");
Console.Write("Enter the string to be transmitted : ");
String str=Console.ReadLine();
Stream stm = tcpclnt.GetStream();
ASCIIEncoding asen= new ASCIIEncoding();
byte[] ba=asen.GetBytes(str);
Console.WriteLine("Transmitting.....");
stm.Write(ba,0,ba.Length);
byte[] bb=new byte[100];
int k=stm.Read(bb,0,100);
for (int i=0;i<k;i++)
Console.Write(Convert.ToChar(bb[i]));
tcpclnt.Close();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}


Is This A Good Question/Topic? 0
  • +

Replies To: possible to control other computer? c#

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: possible to control other computer? c#

Posted 22 August 2012 - 10:25 AM

Since you have the code, don't you already have the answer?
Just try it. Does it work?

If you are writing your own server, and your own client, and your own list of instructions then there is no reason you can't send a command from one of your programs to the other. The receiving computer then does whatever you code it to do. If that is shutdown, so be it. If it is to display the words "Daffy duck talks funny", its not any different.

See FAQ # 9 for client/server tutorials. (Click the SHOW button below)



TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated July 2012
Spoiler



Was This Post Helpful? 0
  • +
  • -

#3 Boosi1  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-July 12

Re: possible to control other computer? c#

Posted 22 August 2012 - 12:30 PM

View PostBoosi1, on 22 August 2012 - 10:19 AM, said:

i didn't understand you so well
i didnt realized how to do what i wanted to...

This post has been edited by tlhIn`toq: 22 August 2012 - 12:38 PM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: possible to control other computer? c#

Posted 22 August 2012 - 12:38 PM

Attached Image

If you can't understand the explanations in English when they are provided, then why are you asking for help on an English speaking forum?

We won't write your client/server protocol for you. Links to sever client/server tutorials were provided. But we won't translate them for you as well. You might try feeding them through translate.google.com
Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10565
  • View blog
  • Posts: 39,103
  • Joined: 27-December 08

Re: possible to control other computer? c#

Posted 22 August 2012 - 02:31 PM

On top of that, this has possible malicious ramifications, which we won't help you with.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1