udpClient = new UdpClient(new IPEndPoint(IPAddress.Any, GlobalConsts.LOCAL_WAIT_PORT));
ThreadStart ts = new ThreadStart(udpWait);
waitThread = new Thread(ts);
waitThread.Start();
}
public void close()
{
waitThread.Abort();
udpClient.Close();
}
private void udpWait()
{
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;
|