public Package CreateCommand(CmdEnum cmd, byte[] param) { Package result = null; switch (cmd) { case CmdEnum.SetColor: result = new Package(1, (int)CmdEnum.SetColor, param); break; } return result; }
private void OnBtnSend_Click(object sender, EventArgs e) { var param = CreateCommonParams(); var pkg = new Package(1, (byte)_cmdEnum, param); Console.WriteLine(pkg); if (!_useUdpProtocol) { if (_port != null && _port.IsOpen) _port.Write(pkg.ToArray(), 0, pkg.Length); } else { if (!String.IsNullOrEmpty(txtAddrAndPort.Text)) { var regex = new Regex(IPAddrAndPort); if (regex.IsMatch(_addrAndPort)) { var ep = CreateIPEndPoint(); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.SendTo(pkg.ToArray(), ep); return; } } MessageBox.Show("Enter IPv4 addr and port in format: XXX.XXX.XXX.XXX:PORTNUM"); } }