IPEndPoint remoteHost = null;
while (udpClient != null && Thread.CurrentThread.ThreadState.Equals(System.Threading.ThreadState.Running ))
{
try
{
byte[] buf = udpClient.Receive(ref remoteHost);
string bufs = Encoding.UTF8.GetString(buf);
if ((bufs.StartsWith("##IP")) && (bufs.EndsWith("#CMD_END##")))
{
int ip_addr_start_pos = bufs.IndexOf("##IP:") + 5;
string ip_address = bufs.Substring(ip_addr_start_pos, bufs.IndexOf("#IPEND#") - ip_addr_start_pos);
int port_start_pos = bufs.IndexOf("##PORT:") + 7;
int port = Convert.ToInt32(bufs.Substring(port_start_pos, bufs.IndexOf("#PORTEND#") - port_start_pos));
//获取传来的ORDER指令,完成对客户端的控制
int order_start_pos = bufs.IndexOf("ORDER:") + 6;
string recvStr = bufs.Substring(order_start_pos, bufs.IndexOf("#CMD_END##") - order_start_pos);
//依据不同的信息来处理客户机
if (recvStr != "")
{
switch (recvStr)
{
case "LOGOUT"://注销本机
DoExitWin(EWX_LOGOFF);
//也可以用下面的方式
//ExitWindowsEx(0, 0);
break;
case "LOCK"://自定义的锁屏方法锁定屏幕//锁定鼠标及键盘//屏蔽ctrl+alt+delete
BlockInput(true);
FileStream fs = new FileStream(Environment.ExpandEnvironmentVariables("%windir%\\system32\\taskmgr.exe"), FileMode.Open);
|