//遥信 public void AsyncSndMsg() { //发送遥信命令 //Session client = (Session)svr.SessionTable[new SessionId(port)]; List <byte> byteSource2 = new List <byte>(); byteSource2.Add(0x68); //启动 byteSource2.Add(0x00); byteSource2.Add(0x00); byteSource2.Add(0x00); byteSource2.Add(0x00); //控制域 byteSource2.Add(0x00); //类型标识,00无返回,01测,10控 byteSource2.Add(0x01); //可变结构限定 byteSource2.Add(0x00); byteSource2.Add(0x22); //传送原因,21遥测,22遥信,23遥控,24延时 byteSource2.Add(0x00); byteSource2.Add(0x01); //公共地址 byteSource2.Add(0x00); byteSource2.Add(0x00); byteSource2.Add(0x10); //信息对象地址 if (switchCheckBox.CheckState == CheckState.Unchecked) { byteSource2.Add(0x00); //信息元素集,遥控 } else { byteSource2.Add(0x01); } byteSource2.Add(0x00000000); byteSource2.Add(0x00000000); byteSource2.Add(0x00000000); byteSource2.Add(0x00000000); byteSource2.Add(0x00000000); byteSource2.Add(0x00000000); //遥测 byteSource2.Insert(1, (byte)(byteSource2.Count() - 1)); //长度 byte[] data = byteSource2.ToArray(); StringBuilder sb = GetSb(data); string info = string.Format("omegaC Send data:{0}.", sb.ToString()); // string info = "发送成功"; if (info == null) { MessageBox.Show("请确保该服务端已正确连接!"); } else { listBox1.Items.Add(info); cli1.Send(data); } }
public void Send(string Message) { string cmd = Message; #region send cli.Send(cmd); #endregion //IsOver = false; }
private void toolStripButtonSend_Click(object sender, EventArgs e) { try { //tc.Send(String.Format("{0}{1}", SendData.Text, Convert.ToChar(4).ToString())); //SendData.Text = String.Format("{0}{1}", SendData.Text.Length.ToString("X8"), SendData.Text); tc.Send(String.Format("{0}", SendData.Text)); rtbe1.SetText(String.Format("Send to [{0}]({1})<<==[{2}]", IPNo.Text, PortNo.Text, SendData.Text), true); } catch (Exception ex) { toolStripStatusLabel1.Text = ex.Message; } }
private void Timer_Connect_Elapsed(object sender, ElapsedEventArgs e) { if (!cli.IsConnected) { try { cli.Connect(Service_IP, Service_Port); StatusMessage = "已连接"; } catch (Exception) { StatusMessage = "连接远程服务器失败"; cli.Close(); } } else { string json = Newtonsoft.Json.JsonConvert.SerializeObject(This_clientConfig); cli.Send(json); } }
/// <summary> /// 客户端登录 /// </summary> public void GetLogin(string uid, string upsw, string uip) { MsgStruts msg = new MsgStruts(); msg.command = msgCommand.GetLogin; msg.msgtype = msgType.SendText; msg.msgsendstate = msgSendState.single; string msgStr = uid + "|" + upsw + "|" + uip; msg.Data = _coder.GetEncodingBytes(msgStr); _tcpcli.Send(msg); }
private void toolStripButtonSend_Click(object sender, EventArgs e) { tc.Send(String.Format("{0}{1}", SendData.Text, Convert.ToChar(4).ToString())); rtbe1.SetText(String.Format("Send to [{0}]({1})<<==[{2}]", IPNo.Text, PortNo.Text, SendData.Text), true); }
public void send(CmdPacket packet) { m_client.Send(packet); m_lstSendTime = Sys_GetTime(); }
public static void Main() { Console.WriteLine("Begin to Test TcpCli Class.."); //ArrayList al = new ArrayList(); TcpClient test = new TcpClient(); TcpCli cli1 = new TcpCli(new Coder(Coder.EncodingMothord.Default)); cli1.Resovlver = new DatagramResolver("]}"); cli1.ReceivedDatagram += new NetEvent(test.RecvData); cli1.DisConnectedServer += new NetEvent(test.ClientClose); cli1.ConnectedServer += new NetEvent(test.ClientConn); try { //命令控制循环 while (true) { Console.Write(">"); string cmd = Console.ReadLine(); if (cmd.ToLower() == "exit") { break; } if (cmd.ToLower() == "close") { //cli.Close(); continue; } if (cmd.ToLower().IndexOf("conn") != -1) { cmd = cmd.ToLower(); string[] para = cmd.Split(' '); if (para.Length != 3) { Console.WriteLine("Error Command"); continue; } try { string conn = para[1]; ushort port = ushort.Parse(para[2]); cli1.Connect(conn, port); } catch (Exception e) { Console.WriteLine(e.Message); } continue; } if (cmd.ToLower().IndexOf("send") != -1) { cmd = cmd.ToLower(); string[] para = cmd.Split(' '); if (para.Length != 2) { Console.WriteLine("Error Command"); } else { try { cli1.Send(para[1]); } catch (Exception ex) { Console.WriteLine(ex.Message); } } continue; } Console.WriteLine("Unkown Command"); }//end of while Console.WriteLine("End service"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }