using GPSBusiness.Helper; using HPSocketCS; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace TextServer { public partial class Form1 : Form { private readonly TcpClient _gpsClient = new TcpClient(); public static bool isConnetion=false; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void btnCon_Click(object sender, EventArgs e) { string ip=this.txtIp.Text; ushort port=Convert.ToUInt16(this.txtPort.Text); if( _gpsClient.Connetion(ip, port, false)){ isConnetion=true; this.btnCon.Text = "已连接"; this.btnCon.Visible = false; } } private void btnSend_Click(object sender, EventArgs e) { string text=this.txtContent.Text; if (isConnetion && !string.IsNullOrEmpty(text)) { byte [] bytes= ByteConvert.hexStringToByte(text); _gpsClient.Send(bytes, bytes.Length); this.lbMsg.Text = "发送成功"; } } } }