|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Net.Sockets;
using System.Net;
namespace ServerX
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ipEntry.AddressList;
ipAddress = addr.First<IPAddress>();
//notifyIcon1.Icon = this.Icon;
lblMYIP.Text = ipAddress.ToString();
}
Thread trSendMessage;
IPAddress ipAddress;
public void SendMessage()
{
string host = txtClientIP.Text;
int port = 63000;
try
{
TcpClient tcpCli = new TcpClient(host, port);
NetworkStream ns = tcpCli.GetStream();
// Send data to the server.
StreamWriter sw = new StreamWriter(ns);
if (rbShutdown.Checked == true)
{
sw.WriteLine("###SHUTDOWN###");
}
if (rbReboot.Checked == true)
{
sw.WriteLine("###REBOOT###");
}
if (rbLogOff.Checked == true)
{
sw.WriteLine("###LOGOFF###");
}
if (rbNothing.Checked == true)
{
sw.WriteLine("to");
}
sw.Flush();
// Receive and display data.
StreamReader sr = new StreamReader(ns);
string result = sr.ReadLine();
if (result == "###OK###")
{
MessageBox.Show("Operation Performed!!!");
}
//MsgBox(result)
sr.Close();
sw.Close();
ns.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnOK_Click(object sender, EventArgs e)
{
if (txtClientIP.Text.Trim()=="")
{
MessageBox.Show("Please enter Client IP Address!!!");
txtClientIP.Focus();
return;
}
if (rbNothing.Checked == false)
{
trSendMessage = new Thread(SendMessage);
trSendMessage.Start();
}
}
private void btnExit_Click(object sender, EventArgs e)
{
try
{
trSendMessage.Abort();
}
catch { }
this.Close();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.