command_string = command_string + "#CMD_END##";
UdpClient sender = new UdpClient();
IPEndPoint endPoint = (new IPEndPoint(IPAddress.Parse(dest_ip_address), GlobalConsts.LOCAL_WAIT_PORT));
try
{
byte[] bytes = Encoding.ASCII.GetBytes(command_string);
sender.Send(bytes, bytes.Length, endPoint);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
sender.Close();
}
}
private void rev_data()
{
rev_data_udp = new UdpClient(new IPEndPoint(IPAddress.Any, local_port));
IPEndPoint remoteHost = null;
while (rev_data_udp != null && Thread.CurrentThread.ThreadState.Equals(ThreadState.Running))
{
try
{
byte[] buf = rev_data_udp.Receive(ref remoteHost);
//以下代码用于取出当前这个数据包对应的屏幕坐标数据
byte[] info = new byte[50];
Array.Copy(buf, 0, info, 0, 50);
string info_data_str = Encoding.UTF8.GetString(info);
int start_pos=info_data_str.IndexOf("#x_1:")+5;
int end_pos=info_data_str.IndexOf("y_1:");
int point_x = Convert.ToInt32(info_data_str.Substring(start_pos, end_pos - start_pos));
start_pos = end_pos + 4;
end_pos = info_data_str.IndexOf("x_2:");
int point_y = Convert.ToInt32(info_data_str.Substring(start_pos, end_pos - start_pos));
Point left_top_point = new Point(point_x, point_y);
|