public static int TxAppPack(byte[] txBuf, int Length) { int num = 200; byte[] numArray = new byte[272]; Console.WriteLine("This is a Client, host name is {0}", (object)Dns.GetHostName()); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(Convert.ToString(FormMain.sCommuAtt.IP0) + (object)'.' + Convert.ToString(FormMain.sCommuAtt.IP1) + (object)'.' + Convert.ToString(FormMain.sCommuAtt.IP2) + (object)'.' + Convert.ToString(FormMain.sCommuAtt.IP3)), FormMain.sCommuAtt.Port); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); if (Length > num) { return(1); } int commuPack = ProtocolDevIo.CreateCommuPack(numArray, txBuf, Convert.ToByte(FormMain.sCommuAtt.ScreenId), Convert.ToByte(FormMain.sCommuAtt.ComNo), Convert.ToByte(Length)); socket.SendTo(numArray, commuPack, SocketFlags.None, (EndPoint)ipEndPoint); EndPoint remoteEP = (EndPoint) new IPEndPoint(IPAddress.Any, 0); socket.ReceiveTimeout = 3; try { int from = socket.ReceiveFrom(CommuUdp.EthentRxBuf, ref remoteEP); socket.Close(); if (from <= 7 || !ProtocolDevIo.CheckCommuPack(CommuUdp.EthentRxBuf, from)) { return(1); } return(CommuUdp.EthentRxBuf[4] == (byte)0 ? 0 : -1); } catch { socket.Close(); return(1); } }
public static int TxAppPack(byte[] txBuf, int Length) { int num = 200; byte[] numArray = new byte[272]; CommuTcp.RxRes = 1; if (!CommuTcp.TcpSocket.Connected || Length > num) { return(CommuTcp.RxRes); } int commuPack = ProtocolDevIo.CreateCommuPack(numArray, txBuf, Convert.ToByte(FormMain.sCommuAtt.ScreenId), Convert.ToByte(FormMain.sCommuAtt.ComNo), Convert.ToByte(Length)); CommuTcp.TcpSocket.BeginSend(numArray, 0, commuPack, SocketFlags.None, (AsyncCallback)null, (object)null); for (int index = 0; index < 100; ++index) { FormMain.DelayMs(30); } return(CommuTcp.RxRes); }