private void Btn_Send_Click(object sender, EventArgs e) { if (tcp.connectedflag) { try { byte[] s = { 0x01, 0x02, 0x03, 0x04, 0x05 }; string stemp = ""; for (int i = 1; i <= s.Length; i++) { if (s[i - 1] < 0x10) { stemp += "0"; } stemp += Convert.ToString(s[i - 1], 16) + " "; } Txt_Recv.Text = "Send : " + stemp + "\n" + Txt_Recv.Text; tcp.recvflag = false; tcp.socket.Send(s); Timer_Init(); } catch { MessageBox.Show("Connect to " + txt_RemoteIP.Text + "failed !"); DisconnectInit_Tcp(); } try { if (tcp.recvflag == true) { Timer_Recv.Stop(); tcp.DataRecv_Show(); if (tcp.DataRecvStr != "") { Txt_Recv.Text = "Recv : " + tcp.DataRecvStr + "\n" + Txt_Recv.Text; } } } catch { DisconnectInit_Tcp(); } } }
private void Timer_Recv_Tick(object sender, EventArgs e) { Txt_Recv.Text = "Recv : Error,Receive time Out ! " + "\n" + Txt_Recv.Text; Timer_Recv.Stop(); tcp.datashowflag = true; }
private void Timer_Init() { Timer_Recv.Stop(); Timer_Recv.Interval = Convert.ToInt32(txt_Time_Out.Text); Timer_Recv.Start(); }